Javascript 如何同时使用JQuery和find?

Javascript 如何同时使用JQuery和find?,javascript,jquery,html,Javascript,Jquery,Html,我正在打印行-列表。在我的每个列中,项目都有2个复选框 <?php for($b=0; $b<$RoomSize["COL"]; $b++){ ?> <div class="col"> <?php $ColKeyExist = checkIfKeyExist($GetSeatLayout, $b, 2); if($RowKeyExist){ if($ColKeyExist){

我正在打印行-列表。在我的每个列中,项目都有2个复选框

<?php
for($b=0; $b<$RoomSize["COL"]; $b++){
?>
    <div class="col">
    <?php
        $ColKeyExist = checkIfKeyExist($GetSeatLayout, $b, 2);
        if($RowKeyExist){
            if($ColKeyExist){
                if($GetSeatLayout[$a]["ROWID"]==$a && $GetSeatLayout[$a]["COLUMNID"]==$b){
    ?>
                  <div id=<?=$a.",".$b?>>
                    <div class="form-check pl-0">
                      <input class="form-check-input" type="checkbox" name="SEATNO" value=<?=$a.",".$b?>>
                      <label class="fas fa-chair SEATIMAGE"></label>
                      <input class="form-check-input" type="checkbox" name="SEATSTATUS" value=0 >
                    </div>
                  </div>
    </div>
    <?php
                }
            }
        }
    ?>
当点击特定的“.col”时,我想让它找到它下面的所有复选框并选中它们,

试试这个

$('.col input[type=checkbox]').each(function (){
  //use one of the below
  $(this).prop('checked', true); 
  $(this).attr('checked', true); // if your jQuery 1.5.x and below
});
试试这个

$('.col input[type=checkbox]').each(function (){
  //use one of the below
  $(this).prop('checked', true); 
  $(this).attr('checked', true); // if your jQuery 1.5.x and below
});

您需要在那里进行一些修改,请参见下面的代码段:

$(文档).ready(函数(){
$(“.col”)。单击(函数(e){
让col=$(this);//此行确保在单击的位置获得外部范围。
col.find('input[type=“checkbox”]”)。每个(函数(a){
col.find('input[type=“checkbox”]')).eq(a).prop('checked','checked');
});    
});
})

您需要在那里进行一些修改,请参见下面的代码片段:

$(文档).ready(函数(){
$(“.col”)。单击(函数(e){
让col=$(this);//此行确保在单击的位置获得外部范围。
col.find('input[type=“checkbox”]”)。每个(函数(a){
col.find('input[type=“checkbox”]')).eq(a).prop('checked','checked');
});    
});
})


@CertainPerformance我删除了它,但它仍然无法读取子元素并找到复选框不确定是否要传递
“checked”
,也许可以尝试传递布尔值,
true
@CertainPerformance它仍然不起作用。我想我设置了属性“checked:checked”是否正确您的代码似乎是“有效的”,因此我建议在
之后添加一个
console.log()
。单击(函数(e)来检查是否触发了单击事件{
你能在浏览器中显示生成html吗?@CertainPerformance我删除了它,但它仍然无法读取子元素并找到复选框不确定是否要传递
“checked”
,也许可以尝试传递布尔值,
true
@CertainPerformance它仍然不起作用。我想我设置了属性“checked:checked”是否更正您的代码似乎“有效”,因此我建议在
之后添加
控制台.log()
。单击(函数(e)以检查是否触发了单击事件{
你能在浏览器中显示生成html吗?这个答案根本不会提供他/她所期望的解决方案。如果有多个.col项,那么你的代码将检查所有这些项,但他/她只需要选中哪个.col。他在复选框内单击了复选框。请查看.col是重复项。@han如果是,你是对的。我正在使用循环和重复项g相同的类/标记/元素,但仅具有不同的值。此答案根本不会提供他/她所期望的解决方案。如果有多个.col项,则您的代码将检查所有这些项,但他/她只希望选中其中的一个。ol他在复选框内单击了复选框。请查看.col是重复项。@han如果是,则您是对的。我正在使用循环和re重复相同的类/标记/元素,但仅使用不同的值。
$(document).ready(function () {
    $(".col").click(function (e) { 
        console.log("success");

        $(this).find('input[type="checkbox"]').each(function (a) {
            var isChecked = $(this).prop('checked');
            if(isChecked == true){
                $(this).prop('checked', false);
            }else if(isChecked == false){
                $(this).prop('checked', true);
            }

        });    
    });
});