Phi*_*ert 5

设置"text"类型的密码文本框:

<input type="text" alt="Enter Password" name="PWD" />
Run Code Online (Sandbox Code Playgroud)

然后使用以下脚本:

$(function() {
   $("input[name=PWD]")
      .focus(function() { $(this).attr("type","password"); })
      .blur(function() { 
          if ($(this).val()) // check if you entered something
             $(this).attr("type","text"); 
       })
      .coolinput();
});
Run Code Online (Sandbox Code Playgroud)

它的作用是:当收到焦点时,文本框变为密码框,当焦点丢失时,它返回到普通文本框(因此提示文本是可读的),除非当然输入了一些内容.文本框.

我实际上没有对此进行测试,但如果它不能正常工作,至少它会指向你的方向.

编辑:

看来你无法使用javascript更改文本框的类型,所以这是一个解决方法:

 <input id="PWD1" name="PWD1" value="Enter password"/>
 <input id="PWD2" name="PWD2" type="password" style="display:none" />
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

$(function() {
   $("#PWD1").focus(function() {  $("#PWD2").show().focus(); $("#PWD1").hide(); });
   $("#PWD2").blur(function() {

     if ($(this).val().length == 0) {
             $("#PWD1").show();
             $("#PWD2").hide();
     }
   });

});
Run Code Online (Sandbox Code Playgroud)

你可以在这里看到它:http://jsbin.com/iniza