首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有cookie的jQuery选项卡-如果存在cookie?

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

Stack Overflow用户
提问于 2011-10-18 08:09:41
回答 2查看 1.2K关注 0票数 5

我有这样的代码:

代码语言:javascript
复制
jQuery(document).ready(function($) {
        $( "#tabs" ).tabs({
            collapsible: true,
            fx: { height: 'toggle', duration: 'fast'},
            cookie: { expires: 30 }
        });
    });

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

我的问题

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-10-18 08:57:35

你应该用一套

代码语言:javascript
复制
//getter
var cookie = $( ".selector" ).tabs( "option", "cookie" );
//setter
$( ".selector" ).tabs( "option", "cookie", { expires: 30 } );

编辑

为Cookie设置名称,并使用getter和setter

代码语言:javascript
复制
 $("#selector").tabs({
        cookie: {
            name: 'mycookie',
            expires: 10
        }
    });


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

        Set the Cookie 
        $.cookie('mycookie', null);
票数 2
EN

Stack Overflow用户

发布于 2011-10-18 08:14:37

你不能用cookie.js的getter方法来做吗:

代码语言:javascript
复制
* 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 

有点像

代码语言:javascript
复制
var cookieVal = $.cookie('ui-tabs-1');
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7804217

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档