0
我有一個滑動菜單,其中滑動了一些div。我們如何獲得cookie中的選定div
在頁面刷新或更改後,我希望該菜單的狀態,因爲它是爲了我使用Cookie。
在那個cookie中,無論我得到什麼值都會影響整個班級,所以我的所有孩子都會出現在屏幕上而不是選定的div上。
我做了一個jsfiddle也審查。檢查here
function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name) {
return unescape(y);
}
}
}
function setCookie(c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays === null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
}
var widget2 = $(".widget2"),
box2 = $(".box2");
var inner = $(".inner"),
box = $(".box");
widget2.hide();
inner.hide();
if(getCookie('box2') == 'on'){
widget2.show();
//alert('hi');
}else{
widget2.hide();
//alert('hiiiiii');
}
if(getCookie('box') == 'on'){
//widget2.show();
inner.show();
alert('hi');
}else{
inner.hide();
//alert('hiiiiii');
}
box2.click(function() {
$(this).next(widget2).slideToggle("fast", function() {
var flag = ($(this).css("display") == 'none')?'off':'on';
setCookie('box2', flag);
});
});
var inner = $(".inner"),
box = $(".box");
box.click(function() {
$(this).next(inner).slideToggle("fast", function() {
var flag = ($(this).css("display") == 'none')?'off':'on';
setCookie('box', flag);
});
});