Javascript 使用jquery 1.10.2选中/取消选中所有复选框
关于这个主题有很多问题,但是没有一个能解决我的问题,因为我不知道如何在我的代码中应用它们——我是jQuery新手 这是我的HTML页面:Javascript 使用jquery 1.10.2选中/取消选中所有复选框,javascript,jquery,checkbox,Javascript,Jquery,Checkbox,关于这个主题有很多问题,但是没有一个能解决我的问题,因为我不知道如何在我的代码中应用它们——我是jQuery新手 这是我的HTML页面: <div id="one"> <div id="positionable2"> <div id="xyz2"> <table id="tab1"> <tr><td class="header"><input type=chec
<div id="one">
<div id="positionable2">
<div id="xyz2">
<table id="tab1">
<tr><td class="header"><input type=checkbox id=cbselectall /></td></tr>
<tr><td ><input type=checkbox name=case /></td></tr>
<tr><td ><input type=checkbox name=case /></td></tr>
<tr><td ><input type=checkbox name=case /></td></tr>
</table>
</div>
</div>
</div>
请注意,表中还有其他列,带有复选框的列是第一列。单击表格标题中的复选框后,应选中数据行上的其他列,反之亦然。不知何故,这是行不通的
由于我是jQuery新手,不知何故我无法让它工作。请提供帮助。首先,您不需要在每个选择器中指定继承人权限
$("#cbselectall").on('click', function() {
$(this)
.parents('table') // go to the table element
.find(':checkbox') /* find all checkboxes (note you might need to specifiy
if you have other checkboxes in the table that shouldn't get checked
*/
.prop('checked', $(this).is(':checked')); /* set the checked value to be the value
of the check all checkbox */
})
JSFIDLE会有所帮助。问题是,您的代码工作正常。问题是:在包含整个页面内容的我的页面中,它不起作用。当我单击标题复选框时,其他复选框未被选中。带有复选框的“我的表”将在加载另一个表后加载。我的jquery在HTML页面的部分。有什么我做错了吗?页面加载后是否使用JavaScript或Ajax动态创建复选框?它不起作用。在加载第一个表后,将动态加载带有复选框的表。这会引起问题吗?请帮忙。谢谢你的解决方案。成功了。我需要将这个jquery放在ajax调用的回调函数中,在这里动态加载这些jquery。非常感谢。
$("#cbselectall").on('click', function() {
$(this)
.parents('table') // go to the table element
.find(':checkbox') /* find all checkboxes (note you might need to specifiy
if you have other checkboxes in the table that shouldn't get checked
*/
.prop('checked', $(this).is(':checked')); /* set the checked value to be the value
of the check all checkbox */
})