Javascript implements the encryption Box Based on the acquisition of focus and the disappearance and display of uncontrolled text _ javascript tips-JS tutorial

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.