jq关于checkbox全选的问题,点击全选一次再点一次取消,然后再这么点全选都没有用了

这是jq代码为什么全选只有第一次点击有效<scripttype="text/javascript">$(".ddd").click(function(){$(this).... 这是jq代码为什么全选只有第一次点击有效 <script type="text/javascript">
$(".ddd").click(function(){ $(this).closest("tr").find("input[type='checkbox']").attr("checked",true); }); $(".noc").click(function(){ $(this).closest("tr").find("input[type='checkbox']").attr("checked",false); });
</script>

上面是html内容因为有很多行所以用的closest
展开
 我来答
yugi111
2015-03-12 · TA获得超过8.1万个赞
知道大有可为答主
回答量:5.1万
采纳率:70%
帮助的人:1.3亿
展开全部
<!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>
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
wwtiger39
2015-03-12 · TA获得超过300个赞
知道小有建树答主
回答量:74
采纳率:0%
帮助的人:96.2万
展开全部

.attr("checked",true);
改成
.prop("checked",true);
就可以了。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式