首先,为了显示 cookie,我使用了 electrictoolbox.com 中的代码.
然后我制作了一个表单来添加一些 cookie:
<form class="cokies" method="post">
<input class="query" name="q" type="text" />
<input type="submit" name="save" value="saving">
<a>Delete Cookies</a>
</form>
$(document).ready(function(){
$('.cokies a').click(function(){
$.cookie('q', null);
});
remember('[name=q]');
该函数来自komodomedia.com :
function remember( selector ){
$(selector).each(function(){
//if this item has been cookied, restore it
var name = $(this).attr('name');
if( $.cookie( name ) ){
$(this).val( $.cookie(name) );
}
//assign a change function to the item to cookie it
$(this).change(function(){
$.cookie(name, $(this).val(), { path: '/', expires: 365 });
});
});
}
问题是,我不知道如何删除 cookie。
最佳答案
要删除 cookie,只需将 expires:
设置为负整数值即可。
示例:
$.cookie(name, $(this).val(), { 路径: '/', 过期时间: -5 });
关于jquery - 如何使用这个 jQuery 插件删除 cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1623728/