利用cookie 实现记住密码功能

@利用cookie 实现记住密码功能

var user = obj.field.username
var password = obj.field.password
var expires = new Date();
//记住密码功能
if(obj.field.remember === "on") {//选中记住密码
	expires.setTime(expires.getTime() + 7 * 24 * 60 * 60 * 1000)  //有效期为7天
}else if(){
	expires.setTime(expires.getTime()-1)   //到期设置
}
document.cookie = 'user=' + user + ',' + password + ';expires=' + expires.toGMTString()


//cookie 取值
$(document).ready(function() {
	var userInfo = document.cookie;
	var username;
	var password;
	if(!userInfo){
		return
	}
	if(userInfo.indexOf(';') != -1) {
		var userInfoArr = userInfo.split(';')
		for(var i = 0; i < userInfoArr.length; i++) {
			if(userInfoArr[i].indexOf('user=') != -1) {
				username = userInfoArr[i].split("=")[1].split(',')[0]
				password = userInfoArr[i].split("=")[1].split(',')[1]
			}
		}
	} else {
		var username = userInfo.split('=')[1].split(',')[0];
		var password = userInfo.split('=')[1].split(',')[1];
	}
	//回显
	$("[name='username']").val(username);
	$("[name='password']").val(password);
	$("[name='remember']").attr('checked', true)

})


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值