Jquery cookie 存在多个按钮集的问题

Jquery cookies issue with multiple buttonsets

本文关键字:问题 按钮 cookie 存在 Jquery      更新时间:2023-09-26

根据这个问题,我自己问并回答了...为 Buttonset 设置 jQuery Cookie我可以为单个按钮组设置 cookie,但现在我正在尝试为多个按钮组做同样的事情。我让它工作,我唯一想不通的是如何选择和刷新按钮集......具有讽刺意味的是,这是我第一个问题遇到的问题,但我想出了该怎么做,这次没有这样的运气。

$(function(){ 
  var radioButtonSet=$('.setCookies').find('.setupRadioButtons');
  radioButtonSet.buttonset();
  var radio=$('.setupRadioButtons').find(':radio'), radioCookieName='selection';
  radio.each(function(){
    var selected=$.cookie(radioCookieName + '|' + this.name);
    $(this).prop('checked', true).button('refresh')  // CAN'T GET THIS TO WORK
    $(this).click(function() {
      $.cookie(radioCookieName + '|' + this.name, $(this).val(), {expires: 365});    
    });
  });
});

好吧,我又一次想通了...

这是工作代码...

$(function(){                                                                                       // Sets cookies for Check boxes
    var radioButtonSet=$('.setCookies').find('.radioButtons');
    radioButtonSet.buttonset();
    var radio=$('.radioButtons').find(':radio');
    radio.each(function(){
        var selected=$.cookie(this.name);
        $('#'+selected).prop('checked', true).button('refresh');
        $(this).click(function() {
            $.cookie(this.name, this.id, {expires: 365});
        });
    });
});