Javascript jQuery,检查是否选择了所有radiobutton组
我有几个RadioButtonGroup,我需要在检查它们时运行脚本 我使用下面的脚本来检查其中一个是否已选中,如果未选中,则将其着色 如何生成代码,以便在选中所有RadioButtonGroup时运行脚本 检查RadioButtonGroup是否已选中的代码:Javascript jQuery,检查是否选择了所有radiobutton组,javascript,jquery,radio-button,Javascript,Jquery,Radio Button,我有几个RadioButtonGroup,我需要在检查它们时运行脚本 我使用下面的脚本来检查其中一个是否已选中,如果未选中,则将其着色 如何生成代码,以便在选中所有RadioButtonGroup时运行脚本 检查RadioButtonGroup是否已选中的代码: $('.aQuestion').each(function(){ if($(this).find('input[type="radio"]:checked').length > 0) { alert("c
$('.aQuestion').each(function(){
if($(this).find('input[type="radio"]:checked').length > 0)
{
alert("checked");
}
else
{
alert("not checked");
}
});
RadioButtonGroup(大约有90个):
1强>
问题
答复1
答复2
答复3
答复4
答复5
2强>
问题
答复1
答复2
答复3
答复4
答复5
提前感谢:D试试这个:
$(document).on('ready change','.aQuestion',function(){
if($(this).find('input[type="radio"]:checked').length > 0)
{
alert("checked");
}
else
{
alert("not checked");
}
});
假设每个问题只有一个单选按钮组,您不需要迭代这些问题以发现它们都被选中:
var $questions = $(".aQuestion");
if($questions.find("input:radio:checked").length === $questions.length) {
// All Checked
}
它演示了上述内容。最终代码:
jQuery('#submit').click(function(event)
{
event.preventDefault();
$('.aQuestion').each(function()
{
if($(this).find('input[type="radio"]:checked').length > 0)
{
$(this).addClass( "madeChoice" ); // Run css that hides the group
}
else
{
$(this).addClass( "didntMakeChoice" ); // Run css that highlight the group.
}
});
var $questions = $(".aQuestion");
if($questions.find("input:radio:checked").length === $questions.length)
{
alert("all checked"); // Send result to DB.
}
else
{
alert("Not Checked"); // Do nothing.
}
});
电台的名字不应该是same@dholakiyaankit否则团队将如何工作?如何开始检查?提交表单时?@dholakiyaankit'name'用于分组,可能您将其与'id'混淆。@Fabricio yes,与submit:jQuery('#submit')。单击(函数(事件)
jQuery('#submit').click(function(event)
{
event.preventDefault();
$('.aQuestion').each(function()
{
if($(this).find('input[type="radio"]:checked').length > 0)
{
$(this).addClass( "madeChoice" ); // Run css that hides the group
}
else
{
$(this).addClass( "didntMakeChoice" ); // Run css that highlight the group.
}
});
var $questions = $(".aQuestion");
if($questions.find("input:radio:checked").length === $questions.length)
{
alert("all checked"); // Send result to DB.
}
else
{
alert("Not Checked"); // Do nothing.
}
});