我有一个(小)问题,我尝试在互联网上查找,但无法找到答案。我是javascript的新手。
HTML:
<form name="examen">
<input type="radio" id="1a" name="1" value="">Answer 1<br></input>
<input type="radio" id="1b" name="1" value="">Answer 2<br></input>
<input type="radio" id="1c" name="1" value="">Answer 3<br></input>
<input type="radio" id="1d" name="1" value="">Answer 4<br></input>
<input type="button" name="knop" value="Bereken" onClick="calculatie()">
</form>
JAVASCRIPT:
function calculatie() {
var calc = "Aantal vragen goed: ";
var totaal = parseInt(0);
if(document.examen.1c.checked){totaal += parseInt(1);}
calc += Math.round(totaal);
alert(calc);
}
现在,当用户点击答案3时,总分数必须为1。但它说NaN,我无法做到。代码需要是JAVASCRIPT / HTML。我无法使用PHP。
答案 0 :(得分:0)
试试这个功能......
function calculatie() {
var calc = "Aantal vragen goed: ";
var totaal = 0;
if(document.getElementById('1c').checked == true){
totaal += 1;}
calc += Math.round(totaal);
console.log(calc); //see console log for output or use it as u want
}
HERE是小提琴
答案 1 :(得分:0)
这是你的js代码:
function calculatie() {
var calc = "Aantal vragen goed: ";
var totaal = 0;
if(document.getElementById("1c").checked){totaal += 1;}
alert(totaal);
};
document.getElementById(&#34; 1c&#34;)返回true或false,weather&#34; Answer 3&#34;被检查与否,如果被检查,将1添加到&#34; totaal&#34;变量