<form id=form" action="" method="get">
<input  type="text" name="First name" value="First name"/>
<input type="text" name="Family name" value="Family name"/>
<input  type="text" name="Email" value="Email..."/>
<input type="text" name="password" value="password..."/>
<input  type="text" name="location" value="City where you live"/>
       <input type="submit" name="sign up" value="Sign Up"/>
</form>
这个是我的源代码。我想在在type="text"的input 实现这样的功能:当鼠标移动到input标签上时,如果文本框的值为最初的value则清空text.否则就微原来输入的值。如果移开鼠标,text栏没有输入任何值就将原来的初始值附上去。怎么实现呀?

解决方案 »

  1.   

    <input type="text" name="First name" value="First name" onMouseOver="javascript:if(this.value != '你设定的初始值') this.value='';" onMouseOut="javascript:if(this.value=='') this.value='你设定的初始值';"/>其他的类似的
      

  2.   

    $( function() {
    $("#txt1").focus(function(){
    this._cache=this.value;
    }).blur(function(){
    if(this.value=="")
    this.value=this._cache;
    });
    });
      

  3.   

    还是类4表单哪样的默认提示:http://mootools.net/forge/p/form_placeholder
      

  4.   

    $( function() {
        $("#txt1").focus(function(){
        if(this.value=="City where you live"){
            this._cache=this.value;
    }
        }).blur(function(){
            if(this.value=="")
                this.value="City where you live";
        });
    });
      

  5.   

    我是一个新手,代码能不能有点注释呀?
    我想要实现的功能是当鼠标点击一个input type=text的框时,第一次的值为默认的value,所有表单清空,如果你没有输入任何值,移开鼠标时文本框的值将是原来默认的值。
      

  6.   

    window.onload= function() {
    var txt1=document.getElementById("txt1"),dv="请输入";
    txt1.value=dv;
    txt1.onfocus= function() {
    //获取焦点时如果value跟默认值相同,清空文本框内容
    if(this.value==dv)
    this.value="";
    };
    txt1.onblur= function() {
    //失去焦点时,如果没有内容还显示默认值
    if(this.value=="")
    this.value=dv;
    };
    };
      

  7.   

    这样做一个input很容易成功,那么多个呢?怎样保存他的值呢?
    多个好像很难实现这样的功能哦
      

  8.   

    $(document).ready(function(){
    //获取焦点时如果value跟默认值相同,清空文本框内容
    $("input").each().focus(function(){
       if(this.value=="City where you live")
      this._cache=this.value;
       })
    //失去焦点时,如果没有内容还显示默认值
    $("input").each().blur(function(){
       if(this.value=="")
       this.value="City where you live";
       })
    })
      

  9.   

    <!DOCTYPE html>
    <html>
    <head>
        <title>test</title>
        <script src="jquery.js"></script>
    </head>
    <body>
        <form id="form" action="" method="get">
    <input type="text" name="First name" value="First name"/>
    <input type="text" name="Family name" value="Family name"/>
    <input type="text" name="Email" value="Email..."/>
    <input type="text" name="password" value="password..."/>
    <input type="text" name="location" value="City where you live"/>
    <input type="submit" name="sign up" value="Sign Up"/>
    </form>
        <script>
         $('#form').children(':text').focus(function(){
         if(!this.initValue){
    this.initValue = this.value;
    }
    if(this.value === this.initValue){
    this.value = '';
    }
         }).blur(function(){
    if(this.value === '' || this.value === null){
    this.value = this.initValue;
    }
    });
        </script>
    </body>
    </html>