登录时用到的,默认显示“密码”,当TextBox获得焦点时,内容清空,TextMode变成Password,用Javascript实现,谁知道

解决方案 »

  1.   

    javascript用的不是TextMode属性,是用type属性,这个属性不可被重设的...
      

  2.   

    直接设置 为 possword啊 [code=HTML] <input type="password" id="text1"/>code]
      

  3.   


    <input type="password" id="text1"/>
    //or
    <asp:TextBox ID="TextBox1"
                runat="server" TextMode="Password"></asp:TextBox>
      

  4.   

    做两个,一个TextBox,一个Password,开一个,关一个!!
    页面代码:
    <asp:TextBox ID="TextBox1" runat="server" onclick="test()">密码</asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server" TextMode="Password" style="display:none"></asp:TextBox>
    js代码:
    <script type="text/javascript">
        function test() {
            document.getElementById("TextBox1").style.display = "none";
            document.getElementById("TextBox2").style.display = "block";
            document.getElementById("TextBox2").focus();
        }
    </script>
      

  5.   

    这个我试过了,页面会走位~~所以我才考虑TextMode的
      

  6.   

    引用错了,应该引用6楼的~~做两个,一个TextBox,一个Password,开一个,关一个!! 
    页面代码: 
    <asp:TextBox ID="TextBox1" runat="server" onclick="test()">密码 </asp:TextBox> 
    <asp:TextBox ID="TextBox2" runat="server" TextMode="Password" style="display:none"> </asp:TextBox> 
    js代码: 
    <script type="text/javascript"> 
        function test() { 
            document.getElementById("TextBox1").style.display = "none"; 
            document.getElementById("TextBox2").style.display = "block"; 
            document.getElementById("TextBox2").focus(); 
        } 
    </script>
      

  7.   

    现在我换个思路,在TextBox2_TextChanged事件中,执行如下代码,结果没反应,高手指点
    string t = TextBox2.Text;
            t=t.Replace("1", "*");
            Response.Write("--" + t);
            //TextBox2.Text = t;
    1是我做测试的,我试输入1,都没反应
      

  8.   

    哦我明白了,你就是想用一个文本框来切换啊,,那我不明白了密码框除了password模式,还能用来干啥呢?我觉得,你可以改变一下业务逻辑
      

  9.   


    <input type="text" id="pwd" name='txtPwd' value="aa" onfocus="change(this)"/>
    <script type="text/javascript">
    var change=function(obj) {
        if(obj.type=="text" && window.ActiveXObject) {
            var pwd=document.createElement("<input name='txtPwd' type='password' />");
            obj.parentNode.replaceChild(pwd,obj);
            setTimeout(function(){pwd.focus();},0);
        } else if(obj.type=="text") {
            obj.value='';
            obj.type='password';
        }
    }
    </script>
      

  10.   

    楼主可以用样式加脚本,文本框有焦点时设置背景图为空,离开时如果文本框没有内容,设置一张有“密码”字样的背景图,这样不就得咯??
    用javascript来设置TextMode这是不可能的~一个是客户端脚本~另一个是服务器属性~
      

  11.   

    如果要用这种方法需要设置TextBox的AutoPostBack为true
    不过还是建议使用javascript好一点~没事别老是访问服务器~哪天服务器发火了~麻烦可就大了
      

  12.   

    这类问题可以移到 javascript 或者 html/css 论坛去问。
      

  13.   


        function bindEvent(){
            $("#password").focus(function(){if($(this).attr('type')=='text'&&$(this).val()=='密码'){
                        var newinput = $('<input type="password" id="password" name="password" class="login_sub"/>');
                        $(this).replaceWith(newinput);
                        newinput.focus();
                        bindEvent();
                    }
                }
            );
            $("#password").blur(
                function(){
                        if($(this).attr('type')=='password'&&$(this).val()==''){
                            $(this).replaceWith('<input type="text" id="password" name="password" value="密码" class="login_sub"/>');
                            bindEvent();
                        }
                    }
                );
        }
      

  14.   

    做这个有意义吗,谁会把密码框加上密码两个字啊,实在要做,就在上面盖个div吧,div透明度设置一下,在div的onClick事件做处理,也真够无聊的,汗。。