Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 选中“全部输入”复选框_Jquery_Html_Checkbox - Fatal编程技术网

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>