Setting and Unsetting Cookies with jQuery
jQuery offers a convenient way to handle cookies:
Set Cookie
Set a cookie named "test" and set its value to 1:
$.cookie("test", 1);
Delete Cookie e
Delete cookie named "test":
$.removeCookie("test");
Advanced options
Set cookie expiration time (here for 10 days):
$.cookie("test", 1, { expires : 10 });
Cover all options:
$.cookie("test", 1, { expires : 10, // 过期时间 path : '/', // 路径 domain : 'jquery.com', // 域名 secure : true // 安全 });
Read Cookie
Read the value of the cookie named "test":
var cookieValue = $.cookie("test");
Updated (2015 4 month)
js-cookie library provides support for jQ A standalone solution for the uery version with the same functionality:
https://github.com/js-cookie/js-cookie
It operates cookies with a similar syntax to the jQuery version.
The above is the detailed content of How Can I Set, Get, and Delete Cookies Using jQuery (and js-cookie)?. For more information, please follow other related articles on the PHP Chinese website!