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