无法删除jquery cookie

无法删除jquery cookie,jquery,cookies,Jquery,Cookies,我使用jquery cookie传递在我的第一个页面上单击的元素的值,以便在下一个页面上使用。我遇到的问题是,每当我将cookie设置为null时,该值都不会删除。它仍然存在 我的第一页上的jquery脚本 <script> $(document).ready(function() { $("div.product-header").click(function() { var index = $("div.product-header").index(thi

我使用jquery cookie传递在我的第一个页面上单击的元素的值,以便在下一个页面上使用。我遇到的问题是,每当我将cookie设置为null时,该值都不会删除。它仍然存在

我的第一页上的jquery脚本

<script>
$(document).ready(function() {
    $("div.product-header").click(function() {
        var index = $("div.product-header").index(this);
        $.cookie("product_name", index);
        //alert("product category: "+$.cookie("product_name"));
    });
    $("div.product-subheader").click(function() {
        var index = $("div.product-subheader").index(this);
        $.cookie("product_subheader", index);
        //alert("product category item: "+$.cookie("product_subheader"));
    });
});
</script>

$(文档).ready(函数(){
$(“div.product-header”)。单击(函数(){
var指数=$(“div.product-header”).指数(本);
$.cookie(“产品名称”,索引);
//警报(“产品类别:+$.cookie(“产品名称”);
});
$(“div.product-subheader”)。单击(函数(){
var指数=$(“部门产品-分目”)。指数(本);
$.cookie(“产品”分标题,索引);
//警报(“产品类别项目:“+$.cookie”(“产品”子标题”);
});
});
将使用cookie的第二页脚本(在此页上cookie正常工作)


$(文档).ready(函数(){
$(“.product contents”).hide();
$('div.product-header').eq($.cookie('product_name')).addClass('active').next().show();
$('div.product-subheader').eq($.cookie('product_subheader')).css({fontwweight:'bold',backgroundColor:'eeeeee');
$('div.product-header')。单击(函数(){
$.cookie('product_name',$('div.product-header')。索引(this));
如果($(this).next()是(':hidden'){
$('div.product-header').removeClass('active').next().hide();
$(this.toggleClass('active').next().show();
}
返回false;
});
});
但是当我尝试使用第二页的脚本时;每当我使用$.cookie(“产品名称”,null)时,cookie不会被删除$.cookie(“产品”子标题,空)cookie仍然没有被删除

<script>
$(document).ready(function() {
    $("div.product-header").click(function() {
        $.cookie("product_name", null);
        alert("cookie product category should be null not: "+$.cookie("product_name"));

        var index = $("div.product-header").index(this);
        $.cookie("product_name", index);
    });

    $("div.product-subheader").click(function() {
        $.cookie("product_subheader", null);
        alert("cookie product category item should be null not: "+$.cookie("product_subheader"));   

        var index = $("div.product-subheader").index(this);
        $.cookie("product_subheader", index);
    });
});
</script>

$(文档).ready(函数(){
$(“div.product-header”)。单击(函数(){
$.cookie(“产品名称”,空);
警报(“cookie产品类别应为空,而不是:“+$.cookie”(“产品名称”);
var指数=$(“div.product-header”).指数(本);
$.cookie(“产品名称”,索引);
});
$(“div.product-subheader”)。单击(函数(){
$.cookie(“产品”子标题,空);
警报(“cookie产品类别项应为空,而不是:+$.cookie(“产品_子标题”));
var指数=$(“部门产品-分目”)。指数(本);
$.cookie(“产品”分标题,索引);
});
});

对我上面的代码有任何更正吗?

设置cookie时,必须指定路径。使用

 $.cookie("product_name", index, { path: '/' });

这将允许您将其从创建cookie的页面以外的页面中删除。

设置cookie时,您必须指定路径。使用

 $.cookie("product_name", index, { path: '/' });
这应该允许您将其从创建cookie的页面以外的页面中删除