Home > Web Front-end > JS Tutorial > jquery.cookie.js Implementation code for operating cookies to realize password remembering function_jquery

jquery.cookie.js Implementation code for operating cookies to realize password remembering function_jquery

WBOY
Release: 2016-05-16 18:07:20
Original
1260 people have browsed it

Copy code The code is as follows:

//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:
Copy code The code is as follows:

$.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
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template