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!