4

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)

4

3 に答える 3

6

私はそれを試していませんでしたが、これはうまくいくはずだと思います:

$("#mytable tr td:nth-child(1) input[type=checkbox]").prop("checked", true);
于 2012-05-13T06:14:09.413 に答える
0

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);
于 2012-05-13T06:06:33.460 に答える
0

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.

于 2012-05-13T06:24:43.143 に答える