通过提交得分

我正在制作一个网站页面,这是一个调查的种类。我有一节主要工作,但我不能得到下半场。我使用了与第一部分相同的代码并进行了扩展。尽管如此,我还是无法使用它。我不明白为什么当我点击提交时不会写分数。当我按下提交时,它应该写下“这是答案”,并且应该从问题的值中计算点的数量,例如,如果他们按下每个问题的第一个单选按钮,它应该打印出2. 2.通过提交得分

这是我使用的基本JavaScript,以防它有所帮助。

function answer(total) { 

var score = 0;

if (document.getElementById('exp_no').checked) {

score++;

}

if (document.getElementById('chg_no').checked) {

score++;

}

if (document.getElementById('sus_no').checked) {

score++;

}

document.getElementById('totalScore').innerHTML = score;

}

这是我正在使用的JavaScript。

function answer2(total) { 

var score2 = 0;

if (document.getElementById('arr_1').checked) {

score2++;

}

else if (document.getElementById('arr_2').checked) {

score2 + 2;

}

else if (document.getElementById('arr_3').checked) {

score2 + 3;

}

else if (document.getElementById('arr_4').checked) {

score2 + 4;

}

else (document.getElementById('arr_5').checked) {

score2 + 5;

}

if (document.getElementById('been1').checked) {

score2++;

}

else if (document.getElementById('been2').checked) {

score2 + 2;

}

else if (document.getElementById('been3').checked) {

score2 + 3;

}

else if (document.getElementById('been4').checked) {

score2 + 4;

}

else if (document.getElementById('been5').checked) {

score2 + 5;

}

if (score2 == 2) {

document.getElementById('finalScore').innerHTML = score2;

} else if (score2 == 4){

document.getElementById('finalScore').innerHTML = score2;

} else if (score2 == 4){

document.getElementById('finalScore').innerHTML = score2;

} else if (score2 == 6){

document.getElementById('finalScore').innerHTML = score2;

} else if (score2 == 8){

document.getElementById('finalScore').innerHTML = score2;

} else if (score2 == 10){

document.getElementById('finalScore').innerHTML = score2;

}

}

这是我的HTML

<button onclick = "toggletab()" id="tabButton"><h3>first results</h3> 

</button>

<form>

<div id="first" >

<fieldset>

<label>

<legend>Is your arrest record a:</legend>

<input id="arr_1" type="radio" name="field4" value="1"

onclick="getscores4(this)"/>

IC 35-38-9-1

</label>

<label>

<input id="arr_2" type="radio" name="field4" value="2"

onclick="getscores4(this)"/>

IC 35-38-9-2

</label>

<label>

<input id="arr_3" type="radio" name="field4" value="3"

onclick="getscores4(this)"/>

IC 35-38-9-3

</label>

<label>

<input id="arr_4" type="radio" name="field4" value="4"

onclick="getscores4(this)"/>

IC 35-38-9-4

</label>

<label>

<input id="arr_5" type="radio" name="field4" value="5"

onclick="getscores4(this)"/>

IC 35-38-9-5

</label>

</fieldset>

<fieldset>

<label>

<legend>Has it been:</legend>

<input id="been1" type="radio" name="field5" value="1"

onclick="getscores5(this)"/>

1 Year From Date of Arrestor earlier if the Prosecutor

agrees

</label>

<label>

<input id="been2" type="radio" name="field5" value="2"

onclick="getscores5(this)"/>

5 Years From Date of Arrestor earlier if the Prosecutor

agrees

</label>

<label>

<input id="been3" type="radio" name="field5" value="3"

onclick="getscores5(this)"/>

8 YearsFrom Date of Arrestor earlier if the Prosecutor

agrees

</label>

<label>

<input id="been4" type="radio" name="field5" value="4"

onclick="getscores5(this)"/>

8/3 Years The Later of 8 Years from Date of Conviction

or 3 years from completion of the sentence or earlier if the Prosecutor

agrees

</label>

<label>

<input id="been5" type="radio" name="field5" value="5"

onclick="getscores5(this)"/>

10/5 Years The Later of 10 Years from Date of

Conviction or 5 years from completion of the sentence or earlier if the

Prosecutor agrees

</label>

</fieldset>

</div>

<fieldset id="submitbutton" class="article">

<input type="button" id="submit" value="submit" onclick='answer2()' />

<p id="finalScore">this is answer </p>

</fieldset>

</form>

</div>

</div>

<script src="backtest.js"></script>

<script src="backtest2.js"></script>

<script src="toggle.js"></script>

回答:

在功能ANSWER2(总数)已宣布名为“score2”变量,但在所有你的逻辑,你正在使用名为“分数”变量。将分数更改为分数2,然后它将起作用。而且我也认为answer2()函数中不需要“全部”参数,因为您没有在任何地方使用它。

以上是 通过提交得分 的全部内容, 来源链接: utcz.com/qa/259226.html

回到顶部