单击“关闭阻止”后,刷新页面时不会保存操作。我究竟做错了什么?
请提示, 提前谢谢。
$(window).load(function(){
// setup the initial display on page load
var menu_state = $.cookie('welcome');
if( typeof menu_state !== "undefined" && menu_state == "hidden" ) {
$('#welcome_block').hide; // visible, and cookie is set
$.cookie('welcome', 'hidden'); // set the cookie
console.log( 'hide' );
console.log( $.cookie('welcome') );
} else {
$('#welcome_block').show; // hidden or cookie is not set, set just in case
$.removeCookie('welcome'); // prevent multiple instances
console.log( 'show' );
}
console.log( $.cookie('welcome') );
$('.disabled').click(function() {
console.log( 'disable block' );
$('#welcome_block').toggle();
$.removeCookie('welcome'); // prevent multiple instances
$.cookie('welcome', 'hidden'); // update (or set) the cookie
$(".disabled").css("display", "none");
$(".enabled").css("display", "block");
//console.log( $.cookie('welcome') );
});
$('.enabled').click(function() {
console.log( 'enable block' );
$('#welcome_block').toggle();
$.removeCookie('welcome'); // prevent multiple instances
$.cookie('welcome', 'visible'); // update (or set) the cookie
$(".disabled").css("display", "block");
$(".enabled").css("display", "none");
//console.log( $.cookie('welcome') );
});
});
答案 0 :(得分:0)
这是JS代码的工作示例HTML:
$(window).load(function(){
// setup the initial display on page load
var menu_state = $.cookie('welcome');
if( (typeof menu_state !== "undefined") && (menu_state == "hidden")) {
$('#welcome_block').css("visibility", "hidden");
$(".enabled").css("display", "block");
// visible, and cookie is set
} else {
$(".enabled").css("display", "none");
$('#welcome_block').css("visibility", "visible")
// hidden or cookie is not set, set just in case
}
$('.disabled').click(function() {
$('#welcome_block').css("visibility", "hidden");
$.removeCookie('welcome'); // prevent multiple instances
$.cookie('welcome', 'hidden'); // update (or set) the cookie
$(".disabled").css("display", "none");
$(".enabled").css("display", "block");
//console.log( $.cookie('welcome') );
});
$('.enabled').click(function() {
$('#welcome_block').css("visibility", "visible");
$.removeCookie('welcome'); // prevent multiple instances
$.cookie('welcome', 'visible'); // update (or set) the cookie
$(".disabled").css("display", "block");
$(".enabled").css("display", "none");
//console.log( $.cookie('welcome') );
}); });