7

これまでのところ、最初の部分を達成しました。次のJavaScriptを使用して、入力タイプをテキストからパスワードに正常に変更しました。

function replaceT(obj) {
        var newO = document.createElement('input');
        newO.setAttribute('type', 'password');
        newO.setAttribute('class', 'textbox');
        newO.setAttribute('name', obj.getAttribute('name'));
        obj.parentNode.replaceChild(newO, obj);
        newO.focus();
    } 

および ASP コード:

<asp:TextBox ID="txtPassword" runat="server" SkinID="txtLogin" value="Password..." TabIndex="2" onfocus="replaceT(this)"></asp:TextBox>

私が欲しいのは第二部です。「 Password...」値 onblurを返す方法。

要するに、Facebook のようなパスワード テキスト ボックスを実装したいと考えています。IE で機能するプレースホルダー属性。

ここでそれがどのように進むかfocus()

ここに画像の説明を入力

フォーカス後:

ここに画像の説明を入力

次に、これに戻りますonblur()

ありがとうございました。

PS

jQuery(純粋なjavascript)なしでこれを実装したいのですが、IE 7以降で作業しています。

4

4 に答える 4

2
<asp:TextBox ID="txtPassword" runat="server" SkinID="txtLogin" value="Password..."placeholder="Enter your password" >

このコードをaspセクションに配置するだけで、javascriptは不要です

編集2:これが役立つことを願っています.ie 10でテストされています

 <html>
 <script>
 function a()
{
document.getElementById("p1").value="";
document.getElementById("p1").type="password";

}

function b()
{
if(document.getElementById("p1").value=="")
{
document.getElementById("p1").type="text";
document.getElementById("p1").value="Password";
}
else
{   
document.getElementById("p1").type="password";

}


}
</script>
<body>
Password:<input type="text" value="Password" onclick="a();" id="p1"         

onblur="b();">
<body>
</html>
于 2013-07-01T06:41:25.423 に答える
1

この小さなプラグインを試してください

 <script>
   $(".contentplaceholder").placeholderContent();
 </script>

フィドルをチェックする

http://jsfiddle.net/Shinov/VdtBs/

純粋な JavaScript プレースホルダーの新しいフィドルを確認してください

http://jsfiddle.net/Shinov/VdtBs/2/

于 2013-07-01T06:30:02.803 に答える