【问题标题】:jQuery tabs with cookie - If cookie exists?带有 cookie 的 jQuery 选项卡 - 如果 cookie 存在?
【发布时间】:2011-12-09 21:25:15
【问题描述】:

我有这个代码:

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

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

我的问题

如何检查标签 cookie 是否设置?

【问题讨论】:

    标签: jquery cookies jquery-ui-tabs jquery-tabs jquery-cookie


    【解决方案1】:

    你不能用 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');
    

    【讨论】:

      【解决方案2】:

      你应该使用 set 和 get

      //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);
      

      【讨论】:

      • 我也这么认为。但它是选项的 Setter/Getter,而不是 cookie :)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      • 2022-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多