开发者

How to select all checkboxes with class "xxx"?

Welcome,

It it possible to select all checkboxes / uncheck all checkboxes what have class "xxx" ?

I can't use "name" and "ID" because there are generated dynamical via PHP and i don't know their name.

So maybye i can add class "xxx" for these what i wan't control ?

Is is possible ?

Or, 开发者_如何学编程if not possible. Maybye i can select all / unselect what are inside table with id "selectall" ?

Regards


Here is how you can do with jquery's attr method:

$('input.xxx').attr('checked', 'checked');

This finds all input elements with class xxx and checks them all. To un-check, them, you could do like:

$('input.xxx').attr('checked', false);

For checkboxes inside a table with id selectall, you can go about like:

$('table#selectall :checkbox').attr('checked', 'checked');

and to un-check them, you should do:

$('table#selectall :checkbox').attr('checked', false);

Or:

$('table#selectall :checkbox').removeAttr('checked');


To select all checkboxes with class "xxx":

$('.xxx:checkbox').attr('checked','checked');

You can use .removeAttr('checked') to unselect them.

To select all checkboxes inside an element with id "selectall":

$('#selectall :checkbox').attr('checked','checked');


If this is for a "select all" you can do something like this:

$("#selectAll").change(function() {
  $(".xxx:checkbox").attr('checked', this.checked);
});

You can test a simple demo here, when you check it, all of the .xxx checkboxes get checked, and unchecked when you unchecked it, this is usually what you want in a "Check/Uncheck All" box at the top.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜