【问题标题】:jQuery ui checkboxes drive me crazyjQuery ui 复选框让我发疯
【发布时间】:2012-10-25 14:17:33
【问题描述】:

我正在使用带有 jQ​​uery UI 复选框的表单,但我遇到了一些问题:

这是我的代码: php

<input type="checkbox" id="check'. $empl->getAttr('id') .'" class="intervenants" /><label for="check'. $empl->getAttr('id') .'">'.$empl->getAttr('nom').'</label>';

javascript

$('.intervenants').each(function() {
    $(this).attr('checked',false);
   });
   for(i = 0; i < data.list_empl.length; i++) {
    $('#check'+data.list_empl[i].id).attr('checked',true);
   }

如您所见,我希望取消选中所有复选框,然后查看数组并尝试仅选中数组中存在的复选框。问题是它不起作用......

我不知道什么不起作用,我试图发出警报,以查看 html,但它看起来完全不连贯。

非常感谢您的帮助,在此先感谢,

卢卡。

【问题讨论】:

    标签: jquery user-interface checkbox checked


    【解决方案1】:

    要使用 jQuery UI,您必须使用:

    $(selector).checkBox('changeCheckStatus',true);
    $(selector).checkBox('changeCheckStatus',false);
    

    【讨论】:

      【解决方案2】:

      选中复选框:

      $(selector).attr('checked', 'checked');
      

      取消选中复选框:

      $(selector).removeAttr('checked');
      

      【讨论】:

      • 在 jQuery 1.6 中,您现在应该使用 $(selector).prop('checked', true);$(selector).prop('checked', false);
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-30
      • 2012-11-02
      • 2020-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多