The example in this article describes how to implement input password box prompt information in js. Share it with everyone for your reference, the details are as follows:
Today our supervisor said that we should add a "please enter password" prompt message in the password box. The first time we thought about using the method of modifying the input type attribute, it turned out that some special browsers did not support it, IE The type attribute of the input is read-only and cannot be set dynamically. So use other methods. The example is as follows:
<input type="text" onfocus="changeTip(this);" id="passText" name="passText" value="请输入密码"/> <input style="display: none;" type="password" onblur="changeTip(this);" id="pass" placeholder="" name="pass" value=""/> <script type="text/javascript"> function changeTip(th){ var passText = document.getElementById('passText'); var pass = document.getElementById('pass'); if(th.id == 'pass'){ if(th.value == '' || th.value.length == 0 ){ passText.style.display=''; pass.style.display='none'; } }else{ passText.style.display='none'; pass.style.display=''; pass.focus(); } } </script>
Supplement:
In fact, the above large section of code can be solved using a placeholder attribute of HTML5. The code is as follows:
PS: Here we recommend a very easy-to-use JavaScript compression, formatting and encryption tool, which is very powerful (for those who want to encrypt their code, you may want to try it Try the js encryption function here):
JavaScript compression/formatting/encryption tool: http://tools.jb51.net/code/jscompress
In addition, the encryption in the above js tool uses the eval function encryption form. For this purpose, this site also provides the following decryption tool for eval function encryption, which is very powerful and practical!
JS eval method online encryption and decryption tool: http://tools.jb51.net/password/evalencode
I hope this article will be helpful to everyone in JavaScript programming.