登录页面通过js判断两次输入的密码是否一致、是否记住密码

window.onload = function(){

//alert("1、OK!");
var oForm = document.getElementById('actionForm');
var oUser = document.getElementById('userCode');
var oPswd = document.getElementById('userPassword');
var oRemember = document.getElementById('remember');

//页面初始化时,如果帐号密码cookie存在则填充
if(getCookie('userCode') && getCookie('userPassword')){
oUser.value = getCookie('userCode');
oPswd.value = getCookie('userPassword');
oRemember.checked = true;

//alert("2、记住密码了吗:"+oRemember.checked);

}

//复选框勾选状态发生改变时,如果未勾选则清除cookie
oRemember.onchange = function(){
if(!this.checked){
delCookie('userCode');
delCookie('userPassword');
//alert("3、未勾选,清除cookies");
}
};

//表单提交事件触发时,如果复选框是勾选状态则保存cookie
oForm.onsubmit = function(){
if(remember.checked){
setCookie('userCode',oUser.value,7); //保存帐号到cookie,有效期7天
setCookie('userPassword',oPswd.value,7); //保存密码到cookie,有效期7天
//alert("4、勾选,保存cookies");
}
};
};

//设置cookie
function setCookie(name,value,day){
var date = new Date();
date.setDate(date.getDate() + day);
document.cookie = name + '=' + value + ';expires='+ date;
//alert("5、设置cookies");
};

//获取cookie
function getCookie(name){
var reg = RegExp(name+'=([^;]+)');
var arr = document.cookie.match(reg);
if(arr){
return arr[1];
}else{
return '';
}
//alert("6、获取cookies");
};

//删除cookie
function delCookie(name){
setCookie(name,null,-1);
//alert("7、删除cookies");
};

你可能感兴趣的:(Java)