需要一个特殊的Jquery Cookie 插件,就可以通过JQuery获取、设置写入cookie
<pre class="brush:jscript;"> $(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
});
```
<h4 style="font-size: 18px;color: rgb(215, 99, 23); ">
获取cookies</h4>
<pre class="brush:jscript;"> $(document).ready(function(){
// Getting the kittens cookie:
var str = $.cookie("kittens");
// str now contains "Seven Kittens"
});
```
<p>
</p>
<h4 style="font-size: 18px; color: rgb(215, 99, 23); ">
删除cookies</h4>
<pre class="brush:jscript;"> $(document).ready(function(){
// Deleting the kittens cookie:
var str = $.cookie("kittens",null);
// No more kittens
});
```
JQuery cookie 获取 设置 写入