无法检查相同 class 的无线电输入?
Trouble checking radio inputs of the same class?
我正处于这个测验的关键时刻,我想开始检查给定的答案并相应地更新分数。但是,当我尝试检查每个问题的输入时,我的测验都停止了。 I have made the correct answer between all the questions have the same class so when that class is chosen they get +1 point.
我的问题是,不同的正确答案之间有相同的 class 是什么导致了这个或其他什么?这是我试图检查每个输入的正确答案的代码:
var checked= $('.CA').checked;
if(checked){
total++;
alert('Your score is '+total);
};
else{
alert('Your score is still '+ total)
};
这是一个适用于的示例问题:
<div id="question1" class="div" name="Q1[0,0]">
<p>What is the capital of Washington?</p>
<input type="radio" class="input" id="answer1a" name="Q">Salem
<br>
<input type="radio" class="input" id="answer1b" name="Q">Seattle
<br>
<input type="radio" class="input" class="CA" name="Q">Olympia
<br>
<input type="radio" class="input" id="answer1d" name="Q">Helena
</div>
这里还有 fiddle。谢谢大家!
您需要一个循环来迭代所有 class CA
尝试这样做
$('.CA').each(function(){
if($(this).is(':checked')){
total++;
alert('Your score is '+total);
};
else{
alert('Your score is still '+ total);
}
});
我正处于这个测验的关键时刻,我想开始检查给定的答案并相应地更新分数。但是,当我尝试检查每个问题的输入时,我的测验都停止了。 I have made the correct answer between all the questions have the same class so when that class is chosen they get +1 point.
我的问题是,不同的正确答案之间有相同的 class 是什么导致了这个或其他什么?这是我试图检查每个输入的正确答案的代码:
var checked= $('.CA').checked;
if(checked){
total++;
alert('Your score is '+total);
};
else{
alert('Your score is still '+ total)
};
这是一个适用于的示例问题:
<div id="question1" class="div" name="Q1[0,0]">
<p>What is the capital of Washington?</p>
<input type="radio" class="input" id="answer1a" name="Q">Salem
<br>
<input type="radio" class="input" id="answer1b" name="Q">Seattle
<br>
<input type="radio" class="input" class="CA" name="Q">Olympia
<br>
<input type="radio" class="input" id="answer1d" name="Q">Helena
</div>
这里还有 fiddle。谢谢大家!
您需要一个循环来迭代所有 class CA
尝试这样做
$('.CA').each(function(){
if($(this).is(':checked')){
total++;
alert('Your score is '+total);
};
else{
alert('Your score is still '+ total);
}
});