Remember password when Web storage--login

Source: Internet
Author: User
Tags sessionstorage

In the login interface, sometimes the front-end to remember the password, where you can use the Web Storage content to achieve. The effect of the implementation is as follows:

    

Here omit the HTML code, mainly write JS code, as follows

1 //code when the page loads2 varStrName = Localstorage.getitem ("KeyName");//obtain a username locally3 varStrpass = Localstorage.getitem ("Keypass");//get the password locally4 if(StrName) {//if the user name exists5$ ("Txtname"). Val (strName);6 }7 if(Strpass) {//If the password exists8$ ("Txtpass"). Val (strpass);9 }Ten //Click the code after login One varStrName = $ ("txtname"). Val (); A varStrpass = $ ("Txtpass"). Val (); -Localstorage.setitem ("KeyName", strName);//Save user name locally - if($ ("Chksave"). Is (': Checked ')) {//Remember the password theLocalstorage.setitem ("Keypass", Strpass);//Save the password locally - } - Else{ -Localstorage.remove ("Keypass");//Remove Password + } -     

To popularize the basics of Web storage, there are two ways to store data on the client: Localstorage and Sessionstorage. They differ from the following

(1) Localstorage is a time-limited way of storing data for persistent local storage, and data is never expired unless the data is actively deleted.

(2) Sessionstorage is used to store data locally in a session, which can only be accessed by a page in the same session, and the data is destroyed when the session ends. So sessionstorage is not a persistent local store, only session-level storage.

(3) Localstorage and Sessionstorage objects have the same properties and methods.

Remember password when Web storage--login

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.