admin管理员组

文章数量:1335357

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 acplish 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)

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 acplish 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)

Share Improve this question asked May 13, 2012 at 6:01 RolandoRolando 62.7k104 gold badges279 silver badges422 bronze badges 1
  • what about removing the colon from between input and the square brackets? – simekadam Commented May 13, 2012 at 6:10
Add a ment  | 

4 Answers 4

Reset to default 6

I think this should work,though I didnt try it out:

$("#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/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".

本文标签: jqueryHow to check all checkboxes in a specific column javascriptStack Overflow