- $(‘.username‘).focus(function(){
- //inputValue为输入的值
- if(!this.inputValue){
- this.inputValue =this.value;
- }
- if(this.value ===this.inputValue){
- this.value =‘‘;
- }
- }).blur(function(){
- if(this.value ===‘‘||this.value ===null){
- this.value =this.inputValue;
- }
- });
其实HTML5新增了一个新属性:placeholder。在HTML代码中增加这一属性,对于不支持该属性的浏览器则可以运用JQ代码来实现。如下:
<inputtype="text"class="username"placeholder="用户名/邮箱地址"value="用户名/邮箱地址"/>