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
4 Answers
Reset to default 6I 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
版权声明:本文标题:jquery - How to check all checkboxes in a specific column javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742225697a2436273.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论