Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.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,我有许多单选按钮,可以选择“是”或“否” 使用jQuery是否有一种简单的方法来检查它们是否都选择了“是” HTML是: <input type="radio" id="yes1" name="group1" value="yes">Yes<br> <input type="radio" name="group1" value="No">No<br> <hr> <input type="radio" id="yes2" name=

我有许多单选按钮,可以选择“是”或“否”

使用jQuery是否有一种简单的方法来检查它们是否都选择了“是”

HTML是:

<input type="radio" id="yes1" name="group1" value="yes">Yes<br>
<input type="radio" name="group1" value="No">No<br>
<hr>
<input type="radio" id="yes2" name="group2" value="yes">Yes<br>
<input type="radio" name="group2" value="No">No<br>
<hr>
<input type="radio" id="yes3" name="group3" value="yes">Yes<br>
<input type="radio" name="group3" value="No">No<br>

您可以将具有
['value=yes]
的元素的长度与具有
['value=yes]
和属性
的元素进行比较:选中

 if($('[value=yes]').length==$('[value=yes]:checked').length){
     //all yes elements are checked
 }

一种方法是检查值为
yes
的所有收音机是否都已检查

if($('input[type="radio"][value="yes"]').not(':checked').length == 0){
    //all checked
}








var yes1=$(“#yes1”)。是(“:选中”) var yes2=$(“#yes2”)。是(“:选中”) var yes3=$(“#yes3”)。是(“:选中”) //$(“#Myradio”)是(“:选中”) 如果(是1、是2、是3){ 警报(“sasa”); //做点什么 }

您可以使用
值检查单选按钮的计数!=正确
。如果计数为零,则会选择所有单选按钮

if(!$('input[type="radio"][value="yes"]').not(':checked').length){
//select all radio buttons with value = yes
}








$(文档).ready(函数(){ $(“#btn”)。单击(函数(){ 变量长度=3; var isChecked=true; 对于(var i=1;i








$(文档).ready(函数(){ $(“#btn”)。单击(函数(){ 变量长度=3; var isChecked=true;
对于(变量i=1;我将
['value=yes]'
更改为
'[value=yes]'
应更改为
'[value=yes]'
<input type="radio" id="yes1" name="group1" value="yes" checked>Yes<br>
<input type="radio" name="group1" value="No">No<br>
<hr>
<input type="radio" id="yes2" name="group2" value="yes" checked>Yes<br>
<input type="radio" name="group2" value="No">No<br>
<hr>
<input type="radio" id="yes3" name="group3" value="yes" checked>Yes<br>
<input type="radio" name="group3" value="No">No<br>


var yes1 = $("#yes1").is(":checked")
    var yes2 = $("#yes2").is(":checked")
    var yes3 = $("#yes3").is(":checked")
    //$("#Myradio").is(":checked")

    if (yes1 & yes2 & yes3) {
        alert('sasa');
       //do something
    }
if(!$('input[type="radio"][value="yes"]').not(':checked').length){
//select all radio buttons with value = yes
}