[英]No style for results of my JavaScript quiz, why?
I produced this psychological test: 我进行了以下心理测验:
<p>Q1: What do you think about XYZ?</p>
<input type="radio" name="group1" id="A1"> Agree strongly<br/>
<input type="radio" name="group1" id="E1"> Disagree very much<br/>
<p>Q1: What do you think about ABC?</p>
<input type="radio" name="group2" id="A2"> Agree strongly<br/>
<input type="radio" name="group2" id="E2"> Disagree very much<br/>
<button onclick="myFunction()">GET RESULTS</button>
<script>
counter = 0;
function myFunction() {
if (document.getElementById('A1').checked){
counter = counter - 2;
} else if (document.getElementById('E1').checked) {
counter = counter + 2;
}
if (document.getElementById('A2').checked){
counter = counter - 2;
} else if (document.getElementById('E2').checked) {
counter = counter + 2;
}
if (counter > 0) {
document.write("Its positive!");
} else {
document.write("Its negative!");
}
}
</script>
When "GET RESULTS" button is clicked results are displayed properly but there is no CSS style applied. 单击“获取结果”按钮时,结果将正确显示,但未应用CSS样式。 What can I do to make results appear on a styled page? 如何使结果显示在样式页面上? Thank you! 谢谢!
Because you used document.write
. 因为您使用了document.write
。
When you use document.write
the entire document, head, body, everything is replaced by whatever you write. 使用document.write
整个文档(头部,正文)时,所有内容都会被您所写的内容所取代。 Therefore you need to recreate a complete document if you use it. 因此,如果使用它,您需要重新创建一个完整的文档。
The standard advise applies: never use document.write()
. 标准建议适用: 切勿使用document.write()
。 Learn about innerHTML
instead (after that read the rest of the DOM API). 而是了解innerHTML
(在此之后阅读DOM API的其余部分)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.