Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.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
单击<;tr>;在jQuery中_Jquery - Fatal编程技术网

单击<;tr>;在jQuery中

单击<;tr>;在jQuery中,jquery,Jquery,我有以下HTML代码: <table class="table table-striped"> <thead> <tr> <th></th> <th>Color</th> </tr> </thead> <tbody> <tr>

我有以下HTML代码:

<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通过再次单击行来恢复支票,请?