Jquery 为什么此代码不删除cookie?
我正在做一件应该相当简单的事情,我正在创建一个cookie,其中包含一组用户定义的变量,并将它们放入一个列表中 然后我尝试允许此人从列表中删除一个项目,这将从cookie中删除它 从列表中删除项目的代码如下所示Jquery 为什么此代码不删除cookie?,jquery,cookies,Jquery,Cookies,我正在做一件应该相当简单的事情,我正在创建一个cookie,其中包含一组用户定义的变量,并将它们放入一个列表中 然后我尝试允许此人从列表中删除一个项目,这将从cookie中删除它 从列表中删除项目的代码如下所示 jQuery('a.removeFromList').live('click', function(){ // put the userList into a holder so I can go through the variable list and only remove
jQuery('a.removeFromList').live('click', function(){
// put the userList into a holder so I can go through the variable list and only remove the one the user clicked
var holdList=userList;
// delete the entire userList
jQuery.cookie('userList',null,{ expires: -1 });
// go through the holdList
for(or=0;or<holdList.items().length;or++){
// this should return "null", but doesn't
alert(userList.items());
if(holdList.items()[or]!=jQuery(this).attr('id')){
// this is a function which adds the data to the cookie.
userList.add(holdList.items()[or]);
}
}
showList(userList,jQuery('ul#userList').data('data'));
});
我正在使用我在这个页面上找到的代码来构建一个逗号分隔的列表,并获取项目。
我还尝试使用userList.clear删除cookie,但也没有成功 jQuery.cookie。。。正在生成“对象不支持此属性或方法”
您是否正确地包含了JQuery cookie插件脚本的链接
这条线也有同样的问题
holdList.items正在生成“对象不支持此属性或方法”您的代码段未找到userList变量定义。也许它会有用。我的意思是告诉我们什么是用户列表如果我理解你看到的doug,那就是你没有包含cookie插件。是的,我有cookie插件。我正在创建烹饪,显示饼干,但无法删除它。还是我误解了你的意思?你的权利一开始我没有。我编辑了对第二个问题的回答。我想从缺少js引用的最简单的解决方案开始。我没有得到这样的错误Doug,我可以通知holdList.items并取回cookie项。