JQuery获取、设置写入cookie
需要一个特殊的Jquery Cookie 插件,就可以通过JQuery获取、设置写入cookie
设置写入cookies
$(document).ready(function(){
// Setting a kittens cookie, it will be lost on browser restart:
$.cookie("kittens","Seven Kittens");
// Setting demoCookie (as seen in the demonstration):
$.cookie("demoCookie",text,{expires: 7, path: '/', domain: 'demo.tutorialzine.com'});
// "text" is a variable holding the string to be saved
});
```
获取cookies
$(document).ready(function(){
// Getting the kittens cookie:
var str = $.cookie("kittens");
// str now contains "Seven Kittens"
});
```
删除cookies
$(document).ready(function(){
// Deleting the kittens cookie:
var str = $.cookie("kittens",null);
// No more kittens
});
```
JQuery cookie 获取 设置 写入