*{margin: 0;padding: 0;} <input type="text" value="123" id="t2" defVal />
<input type="text" id="t1" value="456" defVal /> $("#t1").focus(function(){
if($(this).attr("defVal")==""){
$(this).val("");
$(this).css("color","#555");
}
}).blur(function(){
if($(this).attr("defVal")==""){
$(this).css("color","#eee");
$(this).val("好友名称");
}
else{
$(this).attr("defVal","1");
}
}).keyup(function(){
if($(this).val().length){
$(this).attr("defVal","1");
}
else{
$(this).attr("defVal","");
}
}); $("#t2").focus(function(){
$(this).removeClass("tError");
if($(this).attr("defVal")==""){
$(this).val("");
$(this).css("color","#555");
}
}).blur(function(){
if($(this).attr("defVal")==""){
$(this).css("color","#eee");
$(this).val("请输入手机号码");
}
else{
$(this).attr("defVal","1");
}
}).keyup(function(){
if($(this).val().length){
$(this).attr("defVal","1");
}
else{
$(this).attr("defVal","");
}
});代码比较简单,问题是点获得两个文本框的焦点时,会让文本框向上移动一个像素,请问怎么回事?
<style type="text/css">
*{margin: 0;padding: 0;}
input{float:left}
</style>
<input type="text" value="123" id="t2" defVal />
<input type="text" id="t1" value="456" defVal />