window.Onload=function(){ console.log(document.COOKIE); var COOKIEs = document.COOKIE.split(";"); var userid = document.getElementById("account"); var checkbox = document.getElementById("remeberMe"); for(var i in COOKIEs){ var keyvalue = COOKIEs[i].split("="); if(keyvalue[0]!="user")continue; var username = keyvalue[1].split(":")[0]; var password = keyvalue[1].split(":")[1]; var pswd = document.getElementById("pwd"); userid.value = username; pswd.value=password; } if(userid.value==""){ checkbox.checked =false; } }
// 在提交表单是检查是否需要记住密码
function submitForm(){
var checkbox = document.getElementById("remeberMe");
if(checkbox.checked){ var userid = document.getElementById("account").value; var pswd = document.getElementById("pwd").value; // 记住密码 var date = new Date ( ) ; date . setTime ( date . getTime ( ) + 5 * 24 * 3600 * 1000 ) ; document.COOKIE = "user="+(userid+":"+pswd)+"; expires =" + date.toGMTString (); }else{ document.COOKIE='user=;expires = '+ -1;