Say I have a table with 3 columns, only the 1st and 3rd column of TDs have checkboxes. I have a button that says "SelectAllFirst" that puts a checkmark on all checkboxes in the first column only, the 3rd remains uncheked. How do I accomplish this?
I thought it would be something like this:
$("#mytable tr td:eq(0) input:[type=checkbox]").prop("checked", true);
(but that doesnt do anything. Removing the "eq(0)" results in all checkboxes including the 3rd column to be checked)
我认为这应该有用,虽然我没有尝试过:
$("#mytable tr td:nth-child(1) input[type=checkbox]").prop("checked", true);
td
is the cell, I guess you mean the row. Hard to tell without html though...
$("#mytable tr:eq(0) td input:checkbox").prop("checked", true);
I've created a Fiddle for you here: http://jsfiddle.net/pwCKu/
I believe there are better ways to toggle the check. Just a proof of concept.
$("#checkAll").click(function () {
$(".check").prop('checked', $(this).prop('checked'));
});
This is the code for checking all checkboxes with a checkbox like "select all".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.