gpt4 book ai didi

javascript - TR中选中和取消选中复选框的最佳方法

转载 作者:行者123 更新时间:2023-11-28 11:39:34 24 4
gpt4 key购买 nike

<table>
<tr>
<td><input type="checkbox"></td><td>aa</td><td>ss</td>
</tr>
<tr>
<td><input type="checkbox"></td><td>aa</td><td>ss</td>
</tr>
<tr>
<td><input type="checkbox"></td><td>aa</td><td>ss</td>
</tr>
</table>

直播: http://jsfiddle.net/6U5WH/

如果我使用当前复选框单击 TR,选中和取消选中复选框的最佳方法是什么?是否可以仅使用 HTML(标签?)?如果没有,我想使用 jQuery。

最佳答案

// when the row is clicked toggle the checked property
$('tr').click(function() {
var $cb = $(this).find(':checkbox');
$cb.prop('checked',!$cb.prop('checked'));
});
// prevent a click on the actual checkbox from bubbling to the row
$('tr :checkbox').click( function(e) {
e.stopPropagation();
});

更新的 fiddle :http://jsfiddle.net/6U5WH/1/

关于javascript - TR中选中和取消选中复选框的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8962164/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com