2015-06-17 78 views
0

根據這個問題,我問及自己回答... setting jquery cookies for buttonset 我可以爲單個按鈕集設置Cookie,但現在我想爲多個按鈕集執行相同的操作。我得到它的工作只有我無法弄清楚的是如何選擇和刷新按鈕組......這諷刺的是我遇到的第一個問題,但我想到了如何去做,沒有這樣的運氣這個問題時間。Jquery餅乾問題與多個按鈕

$(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});  
    }); 
    }); 
}); 

回答

0

那麼我再一次想通了......

這裏的工作代碼...

$(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}); 
     }); 
    }); 
});