//Verify whether the password is remembered when initializing the page
$(document).ready(function() {
if ($.cookie("rmbUser") == "true") {
$("#rmbUser").attr("checked", true);
$("#user").val($.cookie("userName"));
$("#pass").val($.cookie("passWord"));
}
});
//Save user information
function saveUserInfo() {
if ($("#rmbUser").attr("checked") == true) {
var userName = $("#user").val();
var passWord = $("#pass").val();
$.cookie("rmbUser", "true", { expires: 7 }); // Store a cookie with a 7-day expiration date
$.cookie("userName", userName, { expires: 7 }); // Store a cookie with a 7-day expiration date
$.cookie("passWord", passWord, { expires: 7 }); // Store a cookie with a 7-day expiration date
}
else {
$.cookie("rmbUser", "false" , { expires: -1 });
$.cookie("userName", '', { expires: -1 });
$.cookie("passWord", '', { expires: -1 });
}
}
The most important lines of code:
$.cookie('the_cookie'); // Read cookie
$.cookie('the_cookie', 'the_value'); // Store cookie
$.cookie('the_cookie', 'the_value', { expires: 7 }); // Store a cookie with a 7-day expiry date
$.cookie('the_cookie', '', { expires: -1 }); // Delete cookie