クッキー付きのjQueryタブ - クッキーが存在する場合は?
-
25-10-2019 - |
質問
私はこのコードを持っています:
jQuery(document).ready(function($) {
$( "#tabs" ).tabs({
collapsible: true,
fx: { height: 'toggle', duration: 'fast'},
cookie: { expires: 30 }
});
});
CookieセットでjQueryタブを使用します。 Cookieが設定されていない場合は、タブを非表示にしたいです。必要なjquery.cookieプラグインをインストールしています。
私の質問
Tabs Cookieが設定されているかどうかを確認するにはどうすればよいですか?
解決
セットを使用して取得します
//getter
var cookie = $( ".selector" ).tabs( "option", "cookie" );
//setter
$( ".selector" ).tabs( "option", "cookie", { expires: 30 } );
編集
クッキーの名前を設定し、ゲッターとセッターを使用します
$("#selector").tabs({
cookie: {
name: 'mycookie',
expires: 10
}
});
Get the Cookie
alert($.cookie('mycookie'));
Set the Cookie
$.cookie('mycookie', null);
他のヒント
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
何かのようなもの
var cookieVal = $.cookie('ui-tabs-1');
所属していません StackOverflow