Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.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
Javascript 当选择框在同一行中被选中时,如何在复选框中自动选择_Javascript_Jquery - Fatal编程技术网

Javascript 当选择框在同一行中被选中时,如何在复选框中自动选择

Javascript 当选择框在同一行中被选中时,如何在复选框中自动选择,javascript,jquery,Javascript,Jquery,当选择框在同一行中被选中时,我想在复选框中自动选择。 虽然我在stackoverflow中发现了这个问题,但不幸的是它不符合我的要求。所以,请给我一些建议 表中有许多行。在每行中,每列中都有一个复选框和一个选择框。如果我在一行的选择框中选择了某个内容,我希望在同一行中执行自动检入复选框 我编写了如下代码 <script> $(document).ready(function() { $('.sel_ActList_status').change(functio

当选择框在同一行中被选中时,我想在复选框中自动选择。 虽然我在stackoverflow中发现了这个问题,但不幸的是它不符合我的要求。所以,请给我一些建议

表中有许多行。在每行中,每列中都有一个复选框和一个选择框。如果我在一行的选择框中选择了某个内容,我希望在同一行中执行自动检入复选框

我编写了如下代码

<script>
    $(document).ready(function() {
        $('.sel_ActList_status').change(function() {
            $('.sel_ActList_status').parent('td').silbings('td').find(".chk_ActList_select").checked = true;
            //$('.sel_ActList_status').parent('td').silbings('td').find(".chk_ActList_select").prop("checked", true);
        });
    });
</script>

<table>
    <tr>
        <td>
            <input id="chk_ActList_select[0]" class="chk_ActList_select" type="checkbox" value="true" name="chk_ActList_select[0]">
        </td>
        <td>xxxxx</td>
        <td>
            <select id="sel_ActList_status" class="sel_ActList_status" name="sel_ActList_status">
                <option selected="selected" value="2">11111</option>
                <option value="0">22222</option>
                <option value="1">33333</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>
            <input id="chk_ActList_select[1]" class="chk_ActList_select" type="checkbox" value="true" name="chk_ActList_select[1]">
        </td>
        <td>xxxxx</td>
        <td>
            <select id="sel_ActList_status" class="sel_ActList_status" name="sel_ActList_status">
                <option value="2">11111</option>
                <option selected="selected" value="0">22222</option>
                <option value="1">33333</option>
            </select>
        </td>
    </tr>
</table>

$(文档).ready(函数(){
$('.sel_ActList_status')。更改(函数(){
$('.sel_ActList_status')。父项('td')。silbings('td')。查找('chk_ActList_select')。选中=真;
//$('.sel_ActList_status').parent('td').silbings('td').find('chk_ActList_select').prop('checked',true);
});
});
xxxxx
11111
22222
33333
xxxxx
11111
22222
33333
但当我在selectbox中选择某个内容时,我的代码无法自动签入复选框。我的jquery代码有什么错误吗?请给我一些指导

提前谢谢。

试试这个

$('.sel_ActList_status').change(function(){
    $(this).parent().parent().find('input[type=checkbox]').attr('checked','checked');
});
$('.sel_ActList_status').change(function() {
    $(this).parent('td').siblings().find(".chk_ActList_select").attr("checked", "true");
});
试试看,这对你很有帮助

$('.sel_ActList_status').change(function(){                                                     
    $(this).closest('tr').find('input:checkbox').prop('checked',true);
 });

简单地说,我建议:

$('select').change(function(){
    $(this).closest('tr').find('input').prop('checked',true);
});

虽然如果您通过选择或更改选择框来启用检查,您可能应该通过相同的路径启用取消检查(只是为了保持一致的UI),因此我将修改
select
元素,添加一个“none”(无)选项
none
),如果选择了该选项,则取消选中该框:

$('select').change(function(){
    var self = this;
    $(this).closest('tr').find('input').prop('checked', self.value !== '-1');
});
.

试试这个

$('.sel_ActList_status').change(function(){
    $(this).parent().parent().find('input[type=checkbox]').attr('checked','checked');
});
$('.sel_ActList_status').change(function() {
    $(this).parent('td').siblings().find(".chk_ActList_select").attr("checked", "true");
});