Domanda

Ho questo codice:

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

Io uso schede jQuery con un set di cookie. Se nessun cookie viene impostato voglio nascondere le schede. Ho installato il plugin jquery.cookie che è stato richiesto.

La mia domanda

Come posso verificare se il cookie schede è impostata oppure no?

È stato utile?

Soluzione

Si shoud utilizzare set e get

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

Modifica

Imposta il nome per il cookie e l'utilizzo getter e setter

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


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

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

Altri suggerimenti

Non potresti farlo con il metodo getter da 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 

Qualcosa di simile

var cookieVal = $.cookie('ui-tabs-1');
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top