我有此代码:

jQuery(document).ready(function($) {
        $( "#tabs" ).tabs({
            collapsible: true,
            fx: { height: 'toggle', duration: 'fast'},
            cookie: { expires: 30 }
        });
    });

我将jQuery选项卡与cookie集使用。如果没有设置cookie,我想隐藏选项卡。我安装了所需的jQuery.cookie插件。

我的问题

如何检查选项卡cookie是否设置了?

有帮助吗?

解决方案

您用套装并获取

//getter
var cookie = $( ".selector" ).tabs( "option", "cookie" );
//setter
$( ".selector" ).tabs( "option", "cookie", { expires: 30 } );

编辑

设置cookie的名称并使用Getter和setter

 $("#selector").tabs({
        cookie: {
            name: 'mycookie',
            expires: 10
        }
    });


        Get the Cookie 
        alert($.cookie('mycookie'));

        Set the Cookie 
        $.cookie('mycookie', null);

其他提示

您无法通过cookie.js的getter方法做到这一点:

* Get the value of a cookie with the given key.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String key The key of the cookie.
* @return The value of the cookie.
* @type String 

就像是

var cookieVal = $.cookie('ui-tabs-1');
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top