Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.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_Html - Fatal编程技术网

Javascript 如果选中一个复选框,请选择另外两个复选框

Javascript 如果选中一个复选框,请选择另外两个复选框,javascript,jquery,html,Javascript,Jquery,Html,该表包含以下几行: <tr> <td> <input type="checkbox" name="indicator[]"> </td> <td> <input type="checkbox" name="graduations[]"> </td> <td> <input type="checkbox" na

该表包含以下几行:

<tr>
    <td>
        <input type="checkbox" name="indicator[]">
    </td>
    <td>
        <input type="checkbox" name="graduations[]">
    </td>
    <td>
        <input type="checkbox" name="graduations[]">
    </td>
    <td>
        <input type="checkbox" name="graduations[]">
    </td>
    <td>
        <input type="checkbox" name="graduations[]">
    </td>
    <td>
        <input type="checkbox" name="graduations[]">
    </td>
</tr>
您可以尝试以下方法:

$("#area_covered").click(function(){
    if($("#area_covered").is(':checked'))
        $('.area_covered').prop('checked', true);
    else
        $('.area_covered').prop('checked', false);  
});
为要单击的复选框指定一些id,并为要选中的其他两个复选框指定一些类。 然后使用上面的jquery标记,它肯定会对您有用\

感谢并享受编码:)

更新尝试这个简单的

让事情变得简单


希望这样做能有所帮助“我需要准确地检查那一行中的两个
刻度
,这是否意味着您必须设置一个锁,以便在不检查2的情况下用户无法继续操作,或者仅将选择限制为2个检查?如果存在一个已检查的
指示器
而没有两个
刻度
则用户无法发送表单,否则
可以简化为
$('.area_covered')。prop('checked',$(this.)。is(':checked'))
;这个问题的完美解决方案+1表单包含与此类似的动态行数。此解决方案仅适用于一行。对吧?对。但我需要一个验证,它不允许在行中选择无刻度或少于2个刻度。
$("#area_covered").click(function(){
    if($("#area_covered").is(':checked'))
        $('.area_covered').prop('checked', true);
    else
        $('.area_covered').prop('checked', false);  
});
 $(function(){
    $("input[name^=graduations]").on("change",function(e){
        if((!$("input[name^=indicator]").is(":checked")) || +$("input[name^=graduations]:checked").length > 2 ){
              $(this).prop('checked',false);
        }
        
    });
     
});