Jquery 选中“全部输入”复选框
这是我的密码:Jquery 选中“全部输入”复选框,jquery,html,checkbox,Jquery,Html,Checkbox,这是我的密码: <SCRIPT language="javascript"> $(function () { $("#selectall").click(function () { $('.name').attr('checked', this.checked); }); $(".name").click(function () { if ($(".name").length == $(".name:checked").length) { $
<SCRIPT language="javascript">
$(function () {
$("#selectall").click(function () {
$('.name').attr('checked', this.checked);
});
$(".name").click(function () {
if ($(".name").length == $(".name:checked").length) {
$("#selectall").attr("checked", "checked");
} else {
$("#selectall").removeAttr("checked");
}
});
});
</SCRIPT>
至于表格:
<td><input type="checkbox" id="selectall"/></td>
<td>No.</td>
<td class="web" width="400" align="center">Name</td>
<td class="web" width="240" align="center">Username</td>
我的问题是,当我单击selectall复选框时,它没有选中所有复选框 看看:
我添加了一些额外的html代码来测试pouposes。这是一个php问题吗?我将使用什么jQuery?@LeRandomGirl发布完整的html代码,因为我们找不到任何名称为类名的元素
$("#selectall").click(function () {
$('.name').attr('checked', this.checked);
});
$(".name").click(function () {
if ($(".name").length == $(".name:checked").length) {
$("#selectall").attr("checked", "checked");
} else {
$("#selectall").removeAttr("checked");
}
});
<input type="checkbox" id="selectall"/> Select All
<table>
<tr>
<td><input type="checkbox" id="1" class="name"/></td>
<td>No.</td>
<td class="web" width="100" align="center">Name</td>
<td class="web" width="140" align="center">Username</td>
</tr>
<tr>
<td><input type="checkbox" id="2" class="name"/></td>
<td>No.</td>
<td class="web" width="100" align="center">Name</td>
<td class="web" width="140" align="center">Username</td>
</tr>
</table>