【发布时间】:2017-04-20 15:46:33
【问题描述】:
我目前正在为自己做一个基本的复习测试,它看起来像这样:
HTML -
<form class="q">
<h4>1. question 1 </h4>
<input name="test" type="radio" value="inc" /> A) 1
<input name="test" type="radio" value="ans"/> B) 2
<input name="test" type="radio" value="inc" /> C) 3
<input name="test" type="radio" value="inc" /> D) 4
<input name="test" type="radio" value="inc" /> E) 5
</form>
<br />
<div class="exp"> a is right </div>
<div class="red"> a is the correct answer</div>
<form class="q">
<h4>1. question 2 </h4>
<input name="test" type="radio" value="inc" /> A) 1
<input name="test" type="radio" value="ans"/> B) 2
<input name="test" type="radio" value="inc" /> C) 3
<input name="test" type="radio" value="inc" /> D) 4
<input name="test" type="radio" value="inc" /> E) 5
</form>
<br />
<div class="exp"> d is right </div>
<div class="red"> d is the correct answer</div>
jQuery -
$(function () {
$('input[name="test"]').on('click', function() {
if ($(this).val() == 'ans') {
$('.exp').show();
$('.red').hide();
} else {
$('.exp').hide();
$('.red').show();
}
})
});
我已经设置好了,当用户选择正确或错误的答案时,会弹出一条消息。
我的问题是,当用户单击第一个问题中的答案时,无论它是正确还是错误,它都会显示两个问题的消息,而不仅仅是单个问题。我想知道如何使它适用于每个问题,而不是一次解决所有问题。
【问题讨论】:
-
因为你没有区分两个问题的信息
标签: javascript jquery html