我需要做一个测验,其中包含2个多项选择题和3个开放词问题(您在框中输入答案),选择题没有问题,但是当我编写开放词问题时,这有些奇怪。我希望它能够识别出如果输入内容正确,那么它将被标记为正确,但是由于某种原因,即使输入错误的答案,它也会自动将我的答案更正为正确的答案。请帮忙,为什么它会自动更正我输入的内容?下面,我将发布我的代码。 (我怀疑代码的错误部分始于document.getElementById("Question3")
<html>
<head>
<title>Quiz!</title>
</head>
<style>
</style>
<script>
function results() {
var score = 0;
if (document.getElementById("q1a").checked) {
score++;
document.getElementById("question1").style = "color: green";
}else{
document.getElementById("question1").style = "color: red";
};
if (document.getElementById("q2d").checked) {
score++;
document.getElementById("question2").style = "color: green";
}else{
document.getElementById("question2").style = "color: red";
};
if (document.getElementById("Question3").value = "In DNA, the concentration of A=T, and C=G.") {
score++;
document.getElementById("question3").style = "color: green";
}else{
document.getElementById("question3").style = "color: red";
};
if (document.getElementById("Question4").value = "An isoelectric point of a protein is the pH of that specific protein when it carries no charge.") {
score++;
document.getElementById("question4").style= "color: green";
}else{
document.getElementById("question4").style = "color: red";
};
if (document.getElementById("Question5").value = "Nucleosides have no phosphate group, unlike nucleotides.") {
score++;
document.getElementById("question5").style = "color: green";
}else{
document.getElementById("question5").style = "color: red";
};
var perc = Math.round((score / 5) * 1000)/10;
document.getElementById("score").innerHTML = "You have "+score+" out of 5 correct!<br/>Your percentage: "+perc+"%";
}
</script>
<body>
<h1>Take the quiz!</h1>
<hr />
<div id="question1">
<h3>Question 1</h3>
<p>Which of the following is an unsaturated hydrocarbon</p>
<p><input type="radio" id="q1a" name="q1" />C2H4<br/>
<input type="radio" id="q1b" name="q1" />CH4<br/>
<input type="radio" id="q1c" name="q1" />CH2<br/>
<input type="radio" id="q1d" name="q1" />CH3COOH</p>
</div>
<div id="question2">
<h3>Question 2</h3>
<p>Do you think that this is a question?</p>
<p><input type="radio" id="q2a" name="q2" />Yes<br/>
<input type="radio" id="q2b" name="q2" />No<br/>
<input type="radio" id="q2c" name="q2" />What?<br/>
<input type="radio" id="q2d" name="q2" />I don't know</p>
</div>
<div id="question3">
<h3>Question 3</h3>
<p>What does the Chargaff Rule state regarding nucleic acids?<input type="text" id="Question3"/></p>
</div>
<div id="question4">
<h3>Question 4</h3>
<p>What is the definition of "Isoelectric Point"?<input type="text" id="Question4"/></p>
</div>
<div id="question5">
<h3>Question 5</h3>
<p>What is the difference between a nucleotide and a nucleoside?<input type="text" id="Question5"/></p>
</div>
<button onClick="results()">Submit</button>
<h1 id="score"></h1>
</body>
</html>