【发布时间】:2014-12-30 13:41:05
【问题描述】:
我正在尝试从我的 HTML 中的图像调用一个函数,想知道是否有人可以解释为什么该函数似乎没有运行?
function markAnswers() {
var intCorrect = 0;
if document.getElementById('question1').value.toUpperCase() = "GROUNDHOG DAY" {
correct = (correct + 1);
}
if document.getElementById('question2').value.toUpperCase() = "CAMERON DIAZ" {
correct = (correct + 1);
}
if document.getElementById('question3').value.toUpperCase() = "BLADE RUNNER" {
correct = (correct + 1);
}
if document.getElementById('question4').value.toUpperCase() = "THE AVENGERS" {
correct = (correct + 1);
}
if document.getElementById('question5').value.toUpperCase() = "WHOOPI GOLDBERG" {
correct = (correct + 1);
}
switch (correct) {
case 0:
alert("You scored 0/5! You weren't even trying!");
break;
case 1:
alert("You scored 1/5! Come on you can do better than that!");
break;
case 2:
alert("You scored 2/5! Well at least you got a couple right!");
break;
case 3:
alert("You scored 3/5! Average...");
break;
case 4:
alert("You scored 4/5! Not bad... Not bad at all!");
break;
case 5:
alert("You scored 5/5!! Perfection!");
break;
default:
alert("Ermm... something went wrong. Well this is awkward.");
}
}
.submitbtn {
background-image: url('../images/markup.png');
width: 221px;
height: 39px;
margin-left: auto;
margin-right: auto;
}
.submitbtn:hover {
background-image: url('../images/markdown.png');
}
<div class="quiz">
<form>
<h3>DOUGHY DRAGON</h3>
<h3 class="answers">GROUNDHOG DAY</h3>
<input type="text" id="question1" name="q1" placeholder="Movie - 2 Words">
<br>
<h3>CORN MAIZE AD</h3>
<h3 class="answers">CAMERON DIAZ</h3>
<input type="text" id="question2" name="q2" placeholder="Actress">
<br>
<h3>NEAR BLUNDER</h3>
<h3 class="answers">BLADE RUNNER</h3>
<input type="text" id="question3" name="q3" placeholder="Movie - 2 Words">
<br>
<h3>SEVENTH GEAR</h3>
<h3 class="answers">THE AVENGERS</h3>
<input type="text" id="question4" name="q4" placeholder="Movie - 2 Words">
<br>
<h3>WORD BOGGLE IHOP</h3>
<h3 class="answers">WHOOPI GOLDBERG</h3>
<input type="text" id="question5" name="q5" placeholder="Actress">
<br>
</form>
<div class="submitbtn" id="submitbutton" onclick="markAnswers()"></div>
</div>
我认为onclick="markAnswers()" 应该调用它。任何帮助将不胜感激!
【问题讨论】:
-
请整理一下缩进-谢谢
-
为什么您的按钮
div中没有任何内容?我们实际上无法点击它 -
“正确”变量未在您的共享代码中初始化。
-
尝试至少在您的 div 中提供
&nbsp;,然后再试一次。 -
请不要提交有语法错误的代码。查看您的控制台以查找并修复这些错误。如果您不知道“控制台”是什么,请立即了解它。事实证明,您的计算机发现语法错误的速度比 SO 的人快得多,因此您可以立即修复它们并继续您的工作。
标签: javascript html css