你好,
我正在尝试编写一个随机报价生成器,但目前无法更改文本。我确定这是一个简单的错误,但任何额外的眼睛都会有所帮助,因为我尝试了我看到的另一种解决方案,但它也没有用,所以我确定我只是遗漏了一些简单的东西。
一如既往地感谢您的帮助,并将分享帮助解决此问题所需的任何其他信息。谢谢!
HTML
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#getMessage").on("click", function(){
$(".message").html("New Message");
});
});
</script>
<link href='http://fonts.googleapis.com/css?family=Lobster+Two' rel='stylesheet' type='text/css'>
<header>
Quote Generator.
</header>
<body>
I thought I'd provide some quotes for your edification.
<div id="wrapper">
<button class = "btn btn-primary" onClick="newQuote()">
Generate New Quote
</button>
</div>
<div class= "text-center">
<div id = "quoteDisplay">
Quote Here
</div>
</div>
<script src = javascript.js></script>
</body>
</html>
CSS
body {
background-image: url("http://www.planwallpaper.com/static/images/depositphotos_15858395-Abstract-swirls-seamless-pattern-background.jpg");
text-align: center;
font-size: 25px;
}
header {
text-align: center;
font-size: 45px;
font: 400 100px/1.3 'Lobster Two', Helvetica, sans-serif;
}
JS
var quotes = ["quote 1", "quote 2", "quote 3"];
function newQuote(){
var randomNumber = Math.floor(Math.random()*(quotes.length()));
document.getElementById('quoteDisplay').innerHTML = quotes[randomNumber];
}
最佳答案
Array.length
是属性,不是函数:
quotes.length()
应该是:
quotes.length
关于javascript - 随机报价按钮不起作用(简单)(HTML、JS、CSS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40229220/