cookie记住用户名密码

时间:2024-04-03 17:04:44

<script src="js/jquery.cookie.js" type="text/javascript"></script>

$(function () {
  if ($.cookie("rmbUser") == "true") {
    $("#remember-me").prop("checked", true);
    $("#user-name").val($.cookie("username")); //用户名
    $("#user-pass").val($.cookie("password")); //密码
  }
})

if ($("#remember-me").prop("checked")) { //是否选中记住用户名密码复选框
  $.cookie("rmbUser", "true", { expires: 1 }); //存储一个带1天期限的cookie
  $.cookie("username", UserName, { expires: 1 });
  $.cookie("password", UserPass, { expires: 1 });
} else {
  $.cookie("rmbUser", "false", { expire: -1 });
  $.cookie("username", "", { expires: -1 });
  $.cookie("password", "", { expires: -1 });
}