gpt4 book ai didi

javascript - appendChild 在 FireFox 中似乎表现不佳

转载 作者:行者123 更新时间:2023-11-28 21:21:14 26 4
gpt4 key购买 nike

我正在尝试学习如何使用 JavaScript 创建 a 作为另一个的子级。我下面的示例在 Chrome 和 IE 中运行良好,但在 Firefox 中,我收到一条错误,提示 JS 中的 viewport.appendChild 行“未定义视口(viewport)”。

html 看起来像这样:

<body>
<div id="viewport"></div>
</body>

JS 看起来像这样:

function createDiv() {

var divTag = document.createElement("div");

divTag.className ="tile";

viewport.appendChild(divTag);

}

最佳答案

那是因为您还没有定义视口(viewport)。在 appendChild 行上方函数的某处添加以下内容:

var viewport=document.getElementById('viewport');

关于javascript - appendChild 在 FireFox 中似乎表现不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6325941/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com