0

我正在使用带有 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,但它看起来完全不连贯。

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

卢卡。

4

2 回答 2

4

要使其与 jQuery UI 一起使用,您必须使用:

$(selector).checkBox('changeCheckStatus',true);
$(selector).checkBox('changeCheckStatus',false);
于 2012-10-04T09:14:51.857 回答
2

要选中复选框:

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

要取消选中复选框:

$(selector).removeAttr('checked');
于 2010-05-28T19:38:37.673 回答