当你写入密码的时候,希望输入的密码不是明文的那么就需要下面的代码 var tx = document.getElementByIdx_x("tx"), pwd = document.getElementByIdx_x("pwd"); tx.onfocus = function(){ if(this.value != "密码") return; this.style.display = "none"; pwd.style.display = ""; pwd.value = ""; pwd.focus(); } pwd.onblur = function(){ if(this.value != "") return; this.style.display = "none"; tx.style.display = ""; tx.value = "密码"; }