2013-12-24 41 views
0

我想安装jQuery饼干,但我无法让它工作。 这里是我使用的代码...设置jquery饼干按钮集

<div id="tabs-5"> 
<form> 
    <fieldset id="units" name="units"> 
    <legend>Units</legend> 
    <center> 
    <div id="radio"> 
     <label title="Select units of measurement to work with, Inches or Millimeters"></label> 
     <label for="inches">Inches</label> 
     <input type="radio" id="inches" name="unit" value="inches" onclick='valInches();' /> 
     <label for="mm">Millimeters</label> 
     <input type="radio" id="mm" name="unit" value="mm" onclick='valMm();' /> 
    </div> 
    </center> 
    </fieldset> <!--end "units"--> 
</form> 
</div> <!-- end tabs-5--> 

$(function() { 
var selected = $.cookie('radio'); // Retrieve cookie value 
    $('input[name="unit"][value="' + selected + '"]').attr('checked', true); //Check matching button 
    $('input[name="unit"]').click(function() { 
    $.cookie('radio', $(this).val(), {expires: 365}); // Save cookie 
    }); 
}); 

回答

0

我发现这个问题是什么......我的代码都工作正常,但问题是按钮并没有获得“点击”。

所以我添加了这个刷新按钮'点击',现在一切工作正常。

$('input[value="' + units + '"]').prop('checked', true).button('refresh'); 

编辑: 设置buttonset类类=单选按钮的代码做什么,我需要的任何buttonset ...

$(function(){                    
    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).change(function() { 
      $.cookie(this.name, $(this).val(), {expires: 365}); 
     }); 
    }); 
});