我有一个登陆页面,想在密码框里显示问题提示用户“ - 请输入密码”,但是密码框是不能显示明文的,所以用js 处理了下!<asp:TextBox ID="txtLoginPwd1" style="height:28px;width:202px;border:#868690 solid 1px;line-height:28px;" Text=" - 请输入密码" onFocus="ChangeUnameNonePwd();" runat="server" TextMode="SingleLine"></asp:TextBox>
                  <asp:TextBox ID="txtLoginPwd" style="height:28px;width:202px;border:#868690 solid 1px;line-height:28px;display:none;"  onblur="ChangeUnameBlockPwd();" runat="server" TextMode="Password"></asp:TextBox>
//鼠标移上txtLoginPwd1隐藏txtLoginPwd1显示txtLoginPwd,并等到焦点
function ChangeUnameNonePwd() {
              var inputname = document.getElementById("<%=txtLoginPwd.ClientID%>");
              var inputname1 = document.getElementById("<%=txtLoginPwd1.ClientID%>");
              inputname1.style.display = "none";
              inputname.style.display = "block";
              inputname.focus();
          }
          function ChangeUnameBlockPwd() {
              var inputname = document.getElementById("<%=txtLoginPwd.ClientID%>");
              var inputname1 = document.getElementById("<%=txtLoginPwd1.ClientID%>");
              inputname.style.display = "none";
              inputname1.style.display = "block";
          }问题来了,IE6下无效,FF下,效果是出来了,可是当鼠标移到txtLoginPwd1上的时候,把txtLoginPwd显示出来了,但是位置比原来要上去一些!
不知道是什么原因!
请教各位大牛,有什么好的办法?

解决方案 »

  1.   

    onfocus="javascript:show();" onblur="javascript:hide();" 显示DIV
    function show()
    {
    var obj=document.getElementById("div1");
    var offsetTop = document.documentElement.scrollTop + event.clientY + 15;      var offsetLeft = event.clientX;
            obj.style.top=offsetTop+"px";
            obj.style.left=offsetLeft+"px";
            obj.style.position="absolute"; 
            obj.style.display="";
            obj.style.width="130px";
            obj.style.height="30px";
            obj.innerText="";
    }
    function hide()
    {
           var obj=document.getElementById("div1");
            obj.style.display="none";
    }
      

  2.   

    使用样式来控制最简单了。做一个有提示的图片,把它设置为背景图即可:<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <style type="text/css">
        .tip{ background-image: url(http://www.guaik.com/i/bg/logo200712.gif)}
        </style>
    </head>
    <body>
    <input type="password" class="tip" style="height: 75px; width:200px;" onfocus="this.className='';" onblur="if( this.value == '') this.className='tip';" />
    </body>
    </html>