【发布时间】:2015-11-10 04:36:24
【问题描述】:
我正在尝试使用随机数生成器从数组中显示一个随机引用,但我遇到了一个错误并且不确定原因。这就是我所拥有的。我知道这可能是重复的,但我觉得它应该打印,但不是。谢谢你的帮助。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Assignment 9</title>
<link href="images/avatar.png" rel="shortcut icon" type="image/png">
<link href="css/stylesheet.css" rel="stylesheet" type="text/css">
<script src="js/javascript.js" type="text/javascript"></script>
<style type="text/css">
</style>
<script type="text/javascript">
</script>
</head>
<body>
<header>
</header>
<aside>
</aside>
<div id="main">
<h1> Arrays and Coditional Statements</h1>
<h2> Quote of the Day</h2>
<p id="demo"></p>
<script>
function myFunction(){
var quote= ["It's not the size of the dog in the fight, It's the size of the fight in the dog",
"Love is the one thing that transcends time and space", "When it rains it pours", "Wake up slow",
" Do not go gentle into that good night; Old age should burn and rave at close of day. Rage, rage against the dying of the light."
];
var randquote= quote[Math.floor(Math.random() * quote.length)];
document.getElementById("demo").innerHTML=randquote;
}
</script>
</div>
<footer>
</footer>
</body>
</html>
【问题讨论】:
-
你永远不会打电话给
myFunction()。 -
是的 - works 如果你真的调用了这个函数。
标签: javascript html arrays