Simple code sharing for remembering password operations during JavaScript Login

Source: Internet
Author: User
This article will share with you a simple section of js Code that enables users to log on and remember password operations. The code is easy to understand and can be used for reference, for more information, see this article. We will share with you a simple js code Implementation # code/6829.html "target =" _ blank "> remember the password operation when you log on. The code is simple and easy to understand, useful for reference. For more information, see

If you don't talk much about it, paste the Code directly. The specific code is as follows:

 
 Remember passwordScript window. onload = function () {var oForm = document. getElementById ('loginform'); var oUser = document. getElementById ('user'); var oPswd = document. getElementById ('pswd '); var oRemember = document. getElementById ('remember'); // when the page is initialized, if the account password cookie exists, enter if (getCookie ('user') & getCookie ('pswd ') {oUser. value = getCookie ('user'); oPswd. value = getCookie ('pswd '); oRemember. checked = true;} // check box When the selected status changes, clear the cookie oRemember. onchange = function () {if (! This. checked) {delCookie ('user'); delCookie ('pswd ') ;}}; // when the form submission event is triggered, if the check box is checked, save the cookie oForm. onsubmit = function () {if (remember. checked) {setCookie ('user', oUser. value, 7); // Save the account to the cookie, valid for 7 days setCookie ('pswd ', oPswd. value, 7); // Save the password to the cookie, valid for 7 days };}; // set the cookie function setCookie (name, value, day) {var date = new Date (); date. setDate (date. getDate () + day); document. cookie = name + '=' + value + '; expires =' + date ;}; // obtain the cookie function getCookie (name) {var reg = RegExp (name + '= ([^;] +)'); var arr = document. cookie. match (reg); if (arr) {return arr [1] ;}else {return '';}; // Delete cookie function delCookie (name) {setCookie (name, null,-1) ;}; script

The above is the detailed content shared by the simple code for logging on to and remembering password operations in JavaScript. For more information, see other related articles in the first PHP community!

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.