【input】 失去焦点时 显示默认值
用户名:当获取焦点时,默认值消失,当失去焦点时,内容为空时,显示默认值。
<input type="text" value="如:admin" id="username">
.username input,.userpwd input{ position:absolute; width:26%; font-size:1.2em; left:15%; margin:0; background:url(../images/login/khfu_khdj_input.png) no-repeat; background-size:100%; line-height:45px;
border:none; text-align:left; height:45px; padding:0 2%; color:#666}
$("#username").focus(function(){ //获取焦点
if ($(this).val()==this.defaultValue){
$(this).val("");
}
}).blur(function(){ //失去焦点
if ($(this).val()==""){
$(this).val(this.defaultValue);
}
})
格式:$("#username").focus(function(){}).blur(function(){});
给心灵一个纯净空间,让思想,情感,飞扬!