jquery implements a password with a short display process and implements the input hint effect

Source: Internet
Author: User

Directory:

I. PURPOSE of realization

Second, the question ponder

Iii. Solutions

1. Enter User name

2, enter the password short display

I. PURPOSE of realization

These days when the project, the customer asked to enter a password in the text box, the password requires a short display process, such as:

second, the question ponder

The first solution is how to implement the hint property in the input box similar to the Android, HTML5 add placeholder, but now is not HTML5, how to do?

Iii. Solutions1. Enter the user name
< Li > <  name= "TextField"  type= "text"  ID= "Usern"   value = "Please enter your user name"   class= "Input userName inputholder"/></li  >

Write a JS:

$.fn.inputholder=function(){    vardval=$ ( This). Val (); $( This). Focus (function(){        $( This). Val ('). addclass (' focous ')); }). blur (function(){        if($( This). val () = = "){            $( This). Val (dval). Removeclass (' focous ');    }        }); };varinputholder=$ ('. Inputholder '));if(inputholder.length) {Inputholder.each (function() {      $( This). Inputholder ()});

When the input box gets focus, the value is emptied, and when the focus is lost, the previously saved value is paid to the input box.

2. Enter password for short display

Found a JS library from the Internet: IPass.packed.js

  The password input is as follows:

 <Li>     <inputname= "Pwdprompt"type= "text"ID= "Textfield2"value= "Please enter your password"class= "Input PassWord inputholder"/>     <inputname= "pwd"type= "Password"ID= "Password"class= "Input PassWord hide"  /></Li>

Since we had previously shown: "Please enter your password" to set the type of input to text so we wrote another input, set its type to password and hide this input.

In the developer tool of the browser we can see:

There will be an input with ID password-0, and this is the IPass.packed.js that we introduced automatically generated.

in my understanding, first write a type of password input, the imported JS will automatically generate a new input on this basis, this input is the type of text, you can display the password. with the type of password we wrote before, input will be combined to implement the short-term password display process.

  Then we add in the Document.ready:

$ (document). Ready (function(){    //To enable IPass plugin$ ("Input[type=password")). IPass (); $("Input[name=pwdprompt]"). Focus (function () {         $("Input[name=pwdprompt]"). Hide (); $("Input[name=password-0]"). Show (). focus ();     }); $("input[name=password-0]"). Blur (function () {         if($( This). val () = = "") {             $("Input[name=pwdprompt]"). Show (); $("Input[name=password-0]"). Hide ();    }     }); });

  Note: This has to be written in Document.ready, not in JS.

  Mainly through the hiding and display to control the display, so that the password short-term display and prompt font hiding function.

jquery implements a password with a short display process and implements the input hint effect

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.