简体   繁体   中英

Why this jQuery cookie doesn't get retrieved?

I have this code for two divs acting like radio buttons, they behave well but the the cookie I set does not get retrieved on page refresh.

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: '/' });
  }
});

if (isboxed = 'isboxed'){应使用== (double-equals)进行比较。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM