带cookie的jQuery选项卡 - 如果cookie存在?

Jen*_*ell 5 cookies jquery jquery-ui-tabs jquery-tabs jquery-cookie

我有这个代码:

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

我使用带有cookie集的jQuery选项卡.如果没有设置cookie,我想隐藏选项卡.我安装了jquery.cookie插件是必需的.

我的问题

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

Ros*_*ena 2

你应该使用 set 和 get

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

编辑

设置 Cookie 的名称并使用 getter 和 setter

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


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

        Set the Cookie 
        $.cookie('mycookie', null);
Run Code Online (Sandbox Code Playgroud)