Javascript 更改不起作用的段落内容

Javascript 更改不起作用的段落内容,javascript,html,Javascript,Html,此代码用于在每次加载页面时更改页面上的引用,但是段落仍然保持为空 <script> (function() { var quotes = [ { text: "This is the first possible quote”" }, { text: "This is the second possible quote”" }, { text: "This is the third possible quote”"

此代码用于在每次加载页面时更改页面上的引用,但是段落仍然保持为空

<script>
(function() {
var quotes = [
    {
    text: "This is the first possible quote”"
    },
    {
    text: "This is the second possible quote”"
    },
    {
    text: "This is the third possible quote”"
    }
    ];
var quoteUse = quotes[Math.floor(Math.random() * quotes.length)];
document.getElementById('quote').innerHTML=quoteUse.text;
})();

我不能评论,因为低代表性,但。确保id=quote的元素存在,并检查控制台是否有错误。

检查开发工具是否有错误F12。您的代码很可能在DOM中的quote元素可用之前运行。将脚本移动到before或使用window.onload=function{…}wrapper。谢谢,我将它移到了末尾,现在它工作得很好。为什么要将引号作为对象放在数组中?只需将字符串放入数组中。。。