奇怪的 HTML 输出
weird HTML output
当我打开html文件时,会出现一个奇怪的输出。
短语o_Matic 说:
这到底是怎么回事? 还有没有用于JS的IDE可以告诉我那里的错误吗?
我正在使用Atom作为我的文本编辑器。
守则 -
<!doctype html>
<html lang="en">
<head>
<title>Phrase-o-matic</title>
<meta charset="utf-8">
<style>
body {
font-family: Verdana , Helvetica ,sans-serif;
}
</style>
<script>
function makePhrases() {
var words1 = ["24/7" , "multi_Tier" , "30,000 foot","B-to-B","win-win"];
var words2 = ["xyz","abcd","batch","retired","morning"];
var words3 = ["super","shot","shake","Sunny"];
var rand1 = Math.floor(Math.random() * words1.length);
var rand2 = Math.floor(math.random() * words2.length);
var rand3 = Math.floor(Math.random() * words3.length);
var phrase = words1[rand1] + " " + words2[rand2] + " " +words3[rand3];
var phraseElement = document.getElementById("phrase");
phraseElement.innerHTML = phrase;
}
window.onload = makePhrases;
</script>
</head>
<body>
<h1>Phrase-o_Matic says;</h1>
<p id="phrase"></p>
</body>
</html>
}
两个错误:
1) 末尾的"}"在关闭的"html"标签之后
2) " var rand2 = Math.floor(math.random() * words2.length);", m 必须像 Math.random() 一样大写。
下面的代码将起作用。
<!doctype html>
<html lang="en">
<head>
<title>Phrase-o-matic</title>
<meta charset="utf-8">
<style>
body {
font-family: Verdana , Helvetica ,sans-serif;
}
</style>
<script>
function makePhrases() {
var words1 = ["24/7" , "multi_Tier" , "30,000 foot","B-to-B","win-win"];
var words2 = ["xyz","abcd","batch","retired","morning"];
var words3 = ["super","shot","shake","Sunny"];
var rand1 = Math.floor(Math.random() * words1.length);
var rand2 = Math.floor(Math.random() * words2.length);
var rand3 = Math.floor(Math.random() * words3.length);
var phrase = words1[rand1] + " " + words2[rand2] + " " +words3[rand3];
var phraseElement = document.getElementById("phrase");
phraseElement.innerHTML = phrase;
}
window.onload = makePhrases;
</script>
</head>
<body>
<h1>Phrase-o_Matic says;</h1>
<p id="phrase"></p>
</body>
</html>
你写var rand2 = Math.floor(math.random() * words2.length);
而不是var rand2 = Math.floor(Math.random() * words2.length);
Math
中有一个小写的"m"表示rand2
。这应该是大写的。
相关文章:
- 使用Jade输出HTML(在ng个重复内)
- 输出 html 表单数据
- 如何通过 AngularJS 模板输出 html
- Ajax 输出 html 注释
- 显示查询输出 HTML 中的图像
- HTML 代码不适用于 jquery 调用,而是输出 HTML 代码
- Html.ActionLink onclick JavaScript 函数未被调用,并且函数名称在输出 HTML 中已损
- Javascript -使用字符串输出HTML
- 如何正确使用jQuery从php输出html字符串
- 为什么.html()不输出html标签
- 如何获得一个变量's输出html值
- Twitter-text.js输出html作为纯文本
- 多行文本文件输出html
- 如何使用XSLT匹配元素和输出HTML
- 输出HTML代码
- 输出HTML时出现意外的令牌错误
- 用JavaScript输出HTML实体
- 在rjerb模板中输出HTML
- 从angularjs过滤器输出HTML,无需ng绑定HTML
- 获取实际输出HTML的函数