Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.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
Jquery 选中单选按钮后自动提交表单_Jquery - Fatal编程技术网

Jquery 选中单选按钮后自动提交表单

Jquery 选中单选按钮后自动提交表单,jquery,Jquery,如何在每个单选按钮组都有选中的单选按钮后自动提交表单?jQuery中是否存在可用于以下场景的内容: <div class="radio-group"> <div class="radio-option"> <input type="radio" class="radioBtn" name="radioBtn1"> </div> <div class="radio-option"> <input type

如何在每个单选按钮组都有选中的单选按钮后自动提交表单?jQuery中是否存在可用于以下场景的内容:

<div class="radio-group">
  <div class="radio-option">
    <input type="radio" class="radioBtn" name="radioBtn1">
  </div>
  <div class="radio-option">
    <input type="radio" class="radioBtn" name="radioBtn1">
  </div>
</div>

<div class="radio-group">
  <div class="radio-option">
    <input type="radio" class="radioBtn" name="radioBtn2">
  </div>
  <div class="radio-option">
    <input type="radio" class="radioBtn" name="radioBtn2">
  </div>
</div>


如果要检查所有组是否都有选中的单选按钮,则可以执行以下操作:

// find all groups
var grps = $( ".radio-group" );    
// next we try find a group with a radio that has no checked item
var hasUnchecked = grps.filter(function(idx, el) {
    // if group has radio button that is checked, 
    // we return false, else - return true 
    return $( el ).find("input:checked")? false : true;
});
// finally in hasUnchecked we have `.radio-group` 
// items with no checked radio found
if (!hasUnchecked) {
    // groups with unchecked radio not found
    // submit a form
}
试试这个

    $(document).ready(function() { $('.radiobtn').change(function(){ 
    if($('.radio-group [type=radio]:checked').length == 2) 
    {
    $('form').submit();
}
     }); 
     });

Onchange
单选按钮,使用
each()
功能可以检查单选组长度是否等于0

$(文档).ready(函数(){
$(“输入:收音机”)。更改(功能(e){
var all_responsed=true;
$(“输入:收音机”)。每个(函数(){
var name=$(this.attr(“name”);
如果($(“输入:收音机[name=“+name+”]:选中”)。长度==0)
{
所有的回答都是假的;
}
});
如果(全部回答==真)
{
警报(“表格提交”);
}
警惕(所有人都回答);
})
});

1.
1.
2.
2.

每次用户单击单选按钮时,都会提交表单。但是OP需要在检查所有组后提交。所以我应该在警报块中添加表单提交代码(表单提交)?。@GpAravindan:你的权利。只需添加$('form')。submit();接近警报
    $(document).ready(function() { $('.radiobtn').change(function(){ 
    if($('.radio-group [type=radio]:checked').length == 2) 
    {
    $('form').submit();
}
     }); 
     });