js记住密码

$(function () {
if (getCookie("rmbUser") == "true") {
 
$("#xuanzong").attr("checked", true);
$("#username").val( getCookie("username"));
$("#password").val(getCookie("password"));
}
});
 
 
 
 
function JiZhu() {
if ($('input[name="checkbox"]').prop("checked")) {
 
var str_username = $("#username").val();
var str_password = $("#password").val();
 
 
setCookie("rmbUser", true,365);
setCookie("username", str_username, 365);
setCookie("password", str_password, 365);
 
} else {
var str_username = "";
var str_password = "";
setCookie("rmbUser", false);
setCookie("username", str_username, 365);
setCookie("password", str_password, 365);
}
}
 
//设置cookie
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
//获取cookie
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1);
if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
}
return "";
}
原文地址:https://www.cnblogs.com/zwyAndDong/p/7372149.html