登录框  有用户名和密码输入框  我想给他一个默认显示的字(请输入用户名 密码),鼠标单击文本框 文字消失  或按键盘上tab键 默认字消失

解决方案 »

  1.   

    你原本设置好val,给input框设置一个onClick或者Mouseover事件,然后把val清空就好啦
      

  2.   

    <INPUT onblur="if(!this.value)this.value='这里也许就有你要的答案... ';return true;" id=search_key onfocus="if(this.value=='这里也许就有你要的答案... ')this.value='';return true;" onkeyup=GoKeyDown(event); value="这里也许就有你要的答案... " size=25 type=text name=key>
      

  3.   


    <input type="text" value="请输入关键字" onblur="if (value ==''){value='请输入关键字'}" onfocus="if (value =='请输入关键字'){value =''}" name="key">
      

  4.   

    <input type="text" value="请输入关键字"
          onfocus="this.value = this.value == this.defaultValue ? '' : this.value;"
          onblur="this.value = this.value == '' ? this.defaultValue : this.value;" />
      

  5.   

    <title>无标题文档</title>
    <script type="text/javascript">
    function init(){
    var username=document.getElementById("username");
    var password=document.getElementById("password");
    username.first=true;
    password.first=true;
    if(username.addEventListener){
    username.addEventListener("focus",ss,false);
    password.addEventListener("focus",ss,false);
    }else if(username.attachEvent){
    username.attachEvent("onfocus",ss);
    password.attachEvent("onfocus",ss);
    }
    }
    function ss(e){
    var a=e||window.event;
    if(a.srcElement){
    if(a.srcElement.first){
    a.srcElement.value="";
    a.srcElement.first=false;
    a.srcElement.style.color="black";
    }
    }else if(a.currentTarget){
    if(a.currentTarget.first)
    a.currentTarget.value="";
    a.currentTarget.first=false;
    a.currentTarget.style.color="black";
    }
    }
    </script>
    </head><body onload="init()">
    <input type="text" value="请输入用户名"id="username" style="color:#999">
    <input type="password" value="请输入密码" id="password" style="color:#999">
    </body>
    </html>
    这样试试