jquery 管理 cookie 的插件
jquery plugin to manage cookies
我必须在我的项目中为不同的产品创建、更新、删除、获取 cookie。那么是否有任何 jquery 插件。现在我正在使用它来管理我项目中的 cookie。
function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
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, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name, "", -1);
}
我需要一个插件,它还可以用新产品及其值更新以前的 cookie。
jQuery cookie 有几个插件。您可以尝试 https://github.com/carhartl/jquery-cookie or https://plugins.jquery.com/cookie/ 或只是 Google。并找到许多其他插件。
我必须在我的项目中为不同的产品创建、更新、删除、获取 cookie。那么是否有任何 jquery 插件。现在我正在使用它来管理我项目中的 cookie。
function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
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, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name, "", -1);
}
我需要一个插件,它还可以用新产品及其值更新以前的 cookie。
jQuery cookie 有几个插件。您可以尝试 https://github.com/carhartl/jquery-cookie or https://plugins.jquery.com/cookie/ 或只是 Google。并找到许多其他插件。