我有两个div的代码,就像单选按钮一样,它们表现良好,但我设置的cookie在页面刷新时无法检索。
var isboxed = $.cookie('boxed_cookie');
if (isboxed = 'isboxed'){
$('.wrap').addClass("boxed");
} else {
$('.wrap').removeClass("boxed");
}
var selectors = $('#sbox-boxed-layout div');
selectors.on('click', function(e){
var $this = $(this);
selectors.removeClass('selected').addClass('disabled');
$this.addClass('selected').removeClass('disabled');
if ($('#sbox-boxed-layout div.on').hasClass('selected')){
$('.wrap').addClass("boxed");
$.cookie('boxed_cookie', 'isboxed' , { expires: 7, path: '/' });
} else {
$('.wrap').removeClass("boxed");
$.cookie('boxed_cookie', 'isfull' , { expires: 7, path: '/' });
}
});
答案 0 :(得分:2)
if (isboxed = 'isboxed'){
应使用==
(双等号)进行比较。