Home >Web Front-end >JS Tutorial >JS realizes the disappearance and display effect of the password box according to the acquisition and loss of focus_javascript skills
The example in this article describes the JS implementation of the disappearance and display effect of the password box based on the acquisition and loss of focus. Share it with everyone for your reference, the details are as follows:
Things:
1. First, temporarily replace the password box with txt and assign the default value 1eb762b98a07c17e3850087a7e763232
2. When the text box gets the focus, clear the default value and change the type to password.
3. When the text box loses focus, change the type to txt and set the default value to "Please enter your password."
JS code:
window.onload=function(){ var input=document.getElementById('input'); input.onfocus=function(){ if(this.value=='请输入密码'){ this.value=''; this.type='password'; }; }; input.onblur=function(){ if(!this.value){ this.type = 'text'; this.value = '请输入密码'; }; }; };
HTML code :
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, 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.