如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script class="jquery library" src="/js/sandbox/jquery/jquery-1.8.2.min.js" type="text/javascript"></script>
<title>
RunJS 演示代码
</title>
<style>
table{
width:100%;
border:1px solid black;
border-collapse:collapse;
}
td th{
border:1px solid black;
}
</style>
<script>
$(document).ready(function(){
$("tr :button:nth-child(1)").click(function(){
$(this).closest("tr").find(":checkbox").prop("checked",true);
});
$("tr :button:nth-child(2)").click(function(){
$(this).closest("tr").find(":checkbox").prop("checked",false);
});
});
</script>
</head>
<body>
<table>
<tr>
<th>
no
</th>
<th>
1
</th>
<th>
2
</th>
<th>
3
</th>
</tr>
<tr>
<td>
11
</td>
<td>
<label>
<input type="checkbox" />
11
</label>
<label>
<input type="checkbox" />
11
</label>
<label>
<input type="checkbox" />
11
</label>
<label>
<input type="checkbox" />
11
</label>
<label>
<input type="checkbox" />
11
</label>
<label>
<input type="checkbox" />
11
</label>
</td>
<td>
11
</td>
<td>
<button>
全选
</button>
<button>
取消
</button>
</td>
</tr>
</table>
</body>
</html>
修改(版本问题)
.attr("checked",true);
改成
.prop("checked",true);
王明昌博客
