开发者

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

开发者 https://www.devze.com 2023-02-08 13:54 出处:网络
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:

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

精彩评论

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