单击<;tr>;在jQuery中
我有以下HTML代码:单击<;tr>;在jQuery中,jquery,Jquery,我有以下HTML代码: <table class="table table-striped"> <thead> <tr> <th></th> <th>Color</th> </tr> </thead> <tbody> <tr>
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th>Color</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="checkbox checkbox-primary">
<input type="checkbox" name="elements_ids">
<label></label>
</div>
</td>
<td>Blue</td>
</tr>
...
</tbody>
</table>
此外,如果选中该复选框,我如何恢复此设置
您能帮忙吗?在点击事件中找到
tr
中的复选框,然后使用prop()
方法设置复选框状态,如下所示
$(“.table tbody tr”)。单击(函数(e){
if($(e.target).is(':checkbox')返回;//单击复选框时忽略
var$cb=$(this.find(':checkbox');
$cb.prop('checked',!$cb.is(':checked');
});代码>
颜色
蓝色
在点击事件中找到tr
中的复选框,然后使用prop()
如下方法设置复选框状态
$(“.table tbody tr”)。单击(函数(e){
if($(e.target).is(':checkbox')返回;//单击复选框时忽略
var$cb=$(this.find(':checkbox');
$cb.prop('checked',!$cb.is(':checked');
});代码>
颜色
蓝色
有一个
以及满足您需要的javascript:
$("tr").on("click", function(e){
$("input[type='checkbox']", this).each( function() {
$(this).attr('checked', !$(this).attr('checked'));
});
});
这样,它将反转单击行上的所有复选框。有一个
以及满足您需要的javascript:
$("tr").on("click", function(e){
$("input[type='checkbox']", this).each( function() {
$(this).attr('checked', !$(this).attr('checked'));
});
});
这样,它将反转单击行上的所有复选框。如果我理解您的问题,您希望当用户单击tr
时,它将选中此tr
中的所有复选框。如果我理解您的问题,您希望当用户单击tr
时,它将选中此tr
中的所有复选框,它可以工作。我只是忘了让ho通过再次单击行来还原支票,好吗?它可以工作。我只是忘了让ho通过再次单击行来恢复支票,请?