【问题标题】:Setting jquery cookies for buttonset为按钮集设置 jquery cookie
【发布时间】:2015-07-10 01:30:27
【问题描述】:

我正在尝试设置 jquery cookie,但无法使其正常工作。 这是我正在使用的代码...

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

【问题讨论】:

    标签: jquery cookies jqueryi-ui-buttonset


    【解决方案1】:

    我发现了问题所在...我的代码工作正常,但问题是按钮没有被“点击”。

    所以我添加了这个来刷新按钮“点击”,现在一切正常。

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

    编辑: 将按钮集类设置为 class=radioButtons 这段代码可以满足我对任何按钮集的需要...

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-20
      • 2017-02-13
      • 2012-04-02
      相关资源
      最近更新 更多