如何在jquery模式对话框中设置cookie

我想在我的modal dialog中添加cookie,但我不知道如何。 我想在24小时内添加cookies,有人可以帮忙吗? 这是modal dialog的代码:

    $(function() { // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore! if ($.cookie('showDialog') == undefined || $.cookie('showDialog') == null || $.cookie('showDialog') != 'false') { $( "#dialog:ui-dialog" ).dialog( "disable" ); $( ".selector" ).dialog({ hide: "slide" }); $( "#dialog-modal" ).dialog({ width:860, height: 420, modal: true, resizable:false, draggable:false }); $.cookie('showDialog', 'false', { expires: 1 }); // set the cookie, with expiry after 1 day } });     

您的代码本身看起来很好,但是您还应该包含对jQuery cookies插件的script引用,因为它不是jQuery的标准部分。

  

您还需要在显示对话框后设置cookie:

 if ($.cookie('showDialog') == undefined || $.cookie('showDialog') == null || $.cookie('showDialog') != 'false') { // show dialog... $.cookie('showDialog', 'false', { expires: 1 }); // set the cookie, with expiry after 1 day }