JQuery uses the type attribute of input to hide and switch passwords.

Source: Internet
Author: User
When you log on to the registration function, you will encounter the need to display the user's user-selected password. How do you achieve this? Today, I will share with you a useful method. jQuery uses the type attribute of the input to implement the hidden switch function of the password display, for more information, see. Generally, we provide a requirement for users to choose whether to display their own passwords during login registration,

In this case, we will surely think that as long as the type attribute of input is dynamically changed (text display/password Hiding ):

So I used$(''#id).attr('type', 'password')However, the results of this API are not what I think, and errors have occurred.

HTML code

Uncaught Error: type property can't be changed

This attribute cannot be modified.

So I just put my hands on googl.

However, the result I got is as follows:

HTML code

 Var showPwd = $ ("# showPwd"), pwd = $ ("# pwd"); showPwd. focus (function () {pwd. show (). focus (); showPwd. hide () ;}); pwd. blur (function () {if (pwd. val () = "") {showPwd. show (); pwd. hide ();}});

In general, this method is used. Simply put, two inputs are used to switch the display back and forth to obtain the characters entered by each other!

I tried this method to implement it, and there are not many codes. But I always think it's strange that such a requirement should be implemented in this way? Certainly not.

In this case, I will check if a large factory is doing this, and some large factories are not doing this!

But Google cannot find my problem, so there is no solution!

The above section describes jQuery's function of hiding and switching passwords by changing the type attribute of input. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. I would like to thank you for your support for PHP chinnet!

For more information about jQuery's function of hiding and switching the password display by changing the type attribute of input, see PHP!

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.