问题描述
我有几个radiobuttongroup,我需要在检查它们时运行一个脚本。
I have several radiobuttongroups, and I need to run a script when they are checked.
我使用以下脚本来检查是否有一个脚本被检查,如果不,然后给它上色。
I use the following script to check if one of them is checked, if not, then color it.
如何制作代码,以便在检查完所有radiobuttongroup后,运行脚本。
How can I make the code, so that when all of the radiobuttongroups are checked, then run script.
检查radiobuttongroups是否被检查的代码:
The code that checks if the radiobuttongroups are checked:
$('.aQuestion').each(function(){
if($(this).find('input[type="radio"]:checked').length > 0)
{
alert("checked");
}
else
{
alert("not checked");
}
});
radiobuttongroups(大约有90个):
The radiobuttongroups (there is about 90 of them):
<div class='aQuestion' id='div1'>
<STRONG>1. </STRONG>
<STRONG>Question</STRONG></br>
<INPUT TYPE='radio' NAME='grp1' VALUE='0'>answer 1</br>
<INPUT TYPE='radio' NAME='grp1' VALUE='1'>answer 2</br>
<INPUT TYPE='radio' NAME='grp1' VALUE='2'>answer 3</br>
<INPUT TYPE='radio' NAME='grp1' VALUE='3'>answer 4</br>
<INPUT TYPE='radio' NAME='grp1' VALUE='4'>answer 5
</div>
<div class='aQuestion' id='div2'>
<STRONG>2. </STRONG>
<STRONG>Question</STRONG></br>
<INPUT TYPE='radio' NAME='grp2' VALUE='0'>answer 1</br>
<INPUT TYPE='radio' NAME='grp2' VALUE='1'>answer 2</br>
<INPUT TYPE='radio' NAME='grp2' VALUE='2'>answer 3</br>
<INPUT TYPE='radio' NAME='grp2' VALUE='3'>answer 4</br>
<INPUT TYPE='radio' NAME='grp2' VALUE='4'>answer 5
</div>
提前致谢:D
推荐答案
假设每个问题只有一个单选按钮组,您不需要重复问题以找出它们全部被选中:
Assuming there is only one radio button group per question, you don't need to iterate the questions in order to find out they're all selected:
var $questions = $(".aQuestion");
if($questions.find("input:radio:checked").length === $questions.length) {
// All Checked
}
演示了上述内容。
这篇关于jQuery,检查是否选中了所有单选按钮组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!