input 输入框获得/失去焦点时隐藏/显示文字

来源:互联网 发布:网络流行语我们不一样 编辑:程序博客网 时间:2024/05/08 04:24
第一种:
 <input type="text" value="搜索关键字" onfocus="if(this.value == '搜索关键字') this.value = ''" onblur="if(this.value =='') this.value = '搜索关键字'" /> 




第二种:

<label>账户名称:</label><input id="account" name="account" type="text" class="txt1 txt" placeholder="请输入5位数字ID或者邮箱">


//获取焦点,取消焦点$('.txt').bind({focus:function(){if (this.value == this.defaultValue){this.value="";}},blur:function(){if (this.value == ""){this.value = this.defaultValue;}}});



0 0
原创粉丝点击