开发者

If one checkbox is selected, automatically select the rest on page jQuery?

If the checkbox with the class "selectAll" is checked I want the rest of the checkboxes on the page to aut开发者_JAVA技巧omatically be checked. I got this working with the following:

$('.selectAll').click(function() {
    $("input[type='checkbox']").attr('checked', true);
});

But I want all checkboxes to be unchecked when select all is clicked again, I can't get that part working. How can that be done?


You could change true to other parameters...

$('.selectAll').click(function() {
    $("input[type='checkbox']").attr('checked', this.checked);
});

(Test: http://jsbin.com/ogobi5)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜