0

我使用谷歌浏览器来查看为什么我的测验结尾不能正常工作以及为什么结果没有显示在文本框中,它说 getResults 没有定义,但对我来说一切正常。还有另一个错误不断出现,它说 Uncaught SyntaxError: Unexpected token ILLEGAL。这个错误是因为 getResults 错误而出现的,还是与完全不同的事情有关?请帮助我非常接近完成测验,但是这必须发生。顺便说一下,这是代码:

<html>
<body>
<h1></h1>
<form>
<ol>
<li> How much are you willing to spend on a phone per month?</li>
<ul>
<li><input type = "radio" name = "q1" id="q1_1"> £5-£10.</input></li> 
<li><input type = "radio" name = "q1" id="q1_2"> £10-£15.</input></li>
<li><input type = "radio" name = "q1" id="q1_3"> £15-£20.</input></li>
<li><input type = "radio" name = "q1" id="q1_4"> £20-£25.</input></li>
<li><input type = "radio" name = "q1" id="q1_5"> £25-£30.</input></li> 
<li><input type = "radio" name = "q1" id="q1_6"> £30-£35.</input></li>
<li><input type = "radio" name = "q1" id="q1_7"> £35-£40.</input></li>
</ul>
<li> Are you good with technology</li>
<ul>
<li><input type = "radio" name = "q2" id="q2_1"> Yes.</input></li>
<li><input type = "radio" name = "q2" id="q2_2"> No.</input></li>
</ul>
<li> Are you looking for an easy to use phone</li>
<ul>
<li><input type = "radio" name = "q3" id="q3_1"> Yes.</input></li>
<li><input type = "radio" name = "q3" id="q3_2"> No.</input></li>
</ul>
<li> Are you looking for a modern type of phone?</li>
<ul>
<li><input type = "radio" name = "q4" id="q4_1"> Yes.</input></li>
<li><input type = "radio" name = "q4" id="q4_2"> No.</input></li>
</ul>
<li> How big do you want the phone to be?</li>
<ul>
<li><input type = "radio" name = "q5" id="q5_1"> Big.</input></li>
<li><input type = "radio" name = "q5" id="q5_2"> Medium.</input></li>
<li><input type = "radio" name = "q5" id="q5_3"> Small.</input></li>
<li><input type = "radio" name = "q5" id="q5_4"> I don't really mind.</input></li>
</ul>
<li> Do you care about the colour of the phone?</li>
<ul>
<li><input type = "radio" name = "q6" id="q6_1"> Yes.</input></li>
<li><input type = "radio" name = "q6" id="q6_2"> No.</input></li>
</ul>
<li> Have you ever owned a phone before?</li>
<ul>
<li><input type = "radio" name = "q7" id="q7_1"> Yes.</input></li>
<li><input type = "radio" name = "q7" id="q7_2"> No.</input></li>
</ul>
<li> Do you want to be able to use the phone to get out of awkward social situations?</li>
<ul>
<li><input type = "radio" name = "q8" id="q8_1"> Yes.</input></li>
<li><input type = "radio" name = "q8" id="q8_2"> No.</input></li>
</ul>
<li> Do you want to be able to access the app store and download apps using your phone?</li>
<ul>
<li><input type = "radio" name = "q9" id="q9_1"> Yes.</input></li>
<li><input type = "radio" name = "q9" id="q9_2"> No.</input></li>
</ul>
<li> What happened to the last phone you owned?</li>
<ul>
<li><input type = "radio" name = "q10" id="q10_1"> I got bored of it.</input></li>
<li><input type = "radio" name = "q10" id="q10_2"> It broke.</input></li>
<li><input type = "radio" name = "q10" id="q10_3"> The contract ran out.</input></li>
<li><input type = "radio" name = "q10" id="q10_4"> Other.</input></li>
</ul>
</ol>
<input type = "button" value = "Submit" onclick="getResults()"> <input type = "reset" value = "Clear"></input>
<textarea id="result">The right phone for you will be displayed here.</textarea>
</html>

<script>
function getResults() {
if (document.getElementById('q1_1').checked &&
   document.getElementById('q2_1').checked &&
   document.getElementById('q3_1').checked &&
   document.getElementById('q4_1').checked &&
   document.getElementById('q5_1').checked &&
   document.getElementById('q6_1').checked &&
   document.getElementById('q7_1').checked &&
   document.getElementById('q8_1').checked &&
   document.getElementById('q9_1').checked &&
   document.getElementById('q10_1').checked
   ) {
       document.getElementById('result').innerHTML = 'Unfortunately, the iPhone is the right phone for you.';
   }
}
</script>
</body>
4

1 回答 1

1

我在 Firefox 的页面源代码查看器中查看了您页面的源代码:

每一个<input>都是错的。你有这个:

<input type = "radio" name = "q1" id="q1_1"> £5-£10.</input>

但尾随</input>是不必要的。你应该有这个:

<input type = "radio" name = "q1" id="q1_1"> £5-£10.

另外:您的结束</html>标签应该是文件中的最后一件事,但您在脚本之前有它。我猜有些浏览器可能会忽略之后的任何内容</html>

你没有结束</form>标签,它应该在你的<script>块之前。

<!doctype html>您可能会发现在页面顶部添加 a以及<head>像这样的块会很有帮助:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

这将整理字符编码,以便您£正确显示。

但是,您没有提到您的页面被嵌入到另一个站点中。因此,您的代码中不需要以下标记:<!doctype>, <html>, </html>, <head>(我建议的整个标题块可以删除), <body>, </body>.

您仍然需要插入</form>缺少的结束标签。

您报告的问题是由于脚本块中的包含页面替换&&为。&#038;&#038;这是脚本块中的语法错误,意味着您的getResults()函数未被解析。您必须检查该站点以了解如何在不发生这种情况的情况下包含脚本。

于 2013-10-20T19:41:58.327 回答