문제

I have this code:

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

I use jQuery tabs with a cookie set. If no cookie is set I want to hide the tabs. I have the jquery.cookie plugin installed that was required.

My question

How can I check if the tabs cookie is set or not?

도움이 되었습니까?

해결책

You shoud use set and get

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

EDIT

Set the name for the Cookie and use getter and setter

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


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

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

다른 팁

Couldn't you do it with the getter method from cookie.js:

* 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 

Something like

var cookieVal = $.cookie('ui-tabs-1');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top