gpt4 book ai didi

javascript - HTML5 和 jQuery 测验逻辑

转载 作者:行者123 更新时间:2023-12-03 01:57:57 25 4
gpt4 key购买 nike

我浏览了几个 StackOverflow 页面,但没有任何帮助。我使用 HTML 单选按钮做了一个测验。问题和答案不是动态生成的。每个问题都有可能的答案,正确答案的值为“正确”。我想检查用户在提交时选择的所有 radio ,如果它们的值 == 向右,那么我想添加一个点(r+=1)。

我的 HTML 看起来像这样 (x9)。

      <div class='col-sm-12 col-md-6 col-lg-4 text-center'>
<p class='question'>Which version of IE supports SSE?</p>
<div class='form-check'>
<input class='form-check-input' type='radio' name='htmlq9a'>
<label class='form-check-label' for='htmlq9a'>Internet explorer 10+</label>
</div>
<div class='form-check'>
<input class='form-check-input' type='radio' name='htmlq9a'>
<label class='form-check-label' for='htmlq9a'>Internet explorer 9+</label>
</div>
<div class='form-check'>
<input class='form-check-input' type='radio' name='htmlq9a'>
<label class='form-check-label' for='htmlq9a'>Internet explorer 8+</label>
</div>
<div class='form-check'>
<input class='form-check-input' type='radio' name='htmlq9a' value='right'>
<label class='form-check-label' for='htmlq9a'>Internet explorer does not support SSE.</label>
</div>
</div>

我的 JavaScript 看起来像这样。

        var r   = 0;
var tr = 9;
var m = 100;
var fs;


$('#sub').click(function(e){
e.preventDefault();
$('input:checked').each(
if( $(this).val() == 'right' ){
r+=1;
}
}
});
var fs = (r/tr) * m;
$('#as').html(fs);

最佳答案

为什么不只检查正确的检查呢?

if ($("input[value=right]").prop("checked")) {
// add points
}

关于javascript - HTML5 和 jQuery 测验逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50152420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com