This article describes how to use JavaScript to determine whether the Password box gets the focus to hide and display the prompt text based on the retrieval of the focus and the disappearance and display of the uncontrolled text, it is very simple and practical. If you need it, you can refer to the example in this article to describe how to get and lose control of the JS implementation Password box based on the focus of the text to disappear and display the effect. We will share this with you for your reference. The details are as follows:
Ideas:
1. Use txt to replace the Password box and assign the default value.
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 type to txt and set the default value to "enter the password ".
JS Code:
Window. onload = function () {var input = document. getElementById ('input'); input. onfocus = function () {if (this. value = 'Enter the password') {this. value = ''; this. type = 'Password' ;};}; input. onblur = function () {if (! This. value) {this. type = 'text'; this. value = 'Enter the password ';};};};
HTML code:
The Code is as follows:
PS:Here we recommend a very useful JavaScript compression, formatting, and encryption tool with powerful functions (for those who want to encrypt code, try the js encryption function here ):
JavaScript compression/formatting/encryption tools:Http://tools.jb51.net/code/jscompress
In addition, the above js tool uses the eval function encryption form for encryption. This site also provides the following decryption tool for eval function encryption, which is very powerful and practical!
Online encryption and decryption tool for js eval Method: Http://tools.jb51.net/password/evalencode
I hope this article will help you design JavaScript programs.