随机报价按钮不工作(简单)(HTML, JS, CSS)

Random Quote Button Not Working (Simple) (HTML, JS, CSS)

本文关键字:HTML JS CSS 简单 工作 随机 按钮      更新时间:2023-09-26

大家好,

我正在尝试编程随机报价生成器,目前无法获得文本更改。我确信这是一个简单的错误,但任何额外的眼睛都会有所帮助,因为我尝试了另一个解决方案,我看到它也不起作用,所以我确信我只是错过了一些简单的东西。

一如既往地感谢您的帮助,并将分享任何其他必要的帮助来解决这个问题。谢谢!

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