用jQuery创build,读取和擦除cookie

可能重复:
如何设置/取消cookie与jQuery?

来人帮帮我。 如何使用jQuery创build,读取和删除一些cookie?

使用COOKIE插件 :

设置一个cookie

$.cookie("example", "foo"); // Sample 1 $.cookie("example", "foo", { expires: 7 }); // Sample 2 $.cookie("example", "foo", { path: '/admin', expires: 7 }); // Sample 3 

获取一个cookie

 alert( $.cookie("example") ); 

删除cookie

 $.removeCookie("example"); 

据我所知,没有直接的支持,但你可以使用普通的醇'JavaScript的:

  // Cookies 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); } 

Google是我的朋友,它向我展示了这个页面:

使用jQuery的Cookie插件,链接作为今天工作: https : //github.com/js-cookie/js-cookie