gpt4 book ai didi

javascript - getElementById 出现错误

转载 作者:行者123 更新时间:2023-11-28 11:34:37 25 4
gpt4 key购买 nike

我必须执行两个图像切换的动画。镜像ID为image_anim .

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Chill</title>
<link rel="stylesheet" type="text/css" href="../css/Start_Page_css.css"/>
<script src="../Java_Script/button_click.js"></script>
<script type="text/javascript">
var boxOne = document.getElementsById("image_anim");
setTimeout(function()
{

for (var i=0;i<4;i++) {
setTimeout(function()
{

setTimeout(function()
{
boxOne.src="../Images/p1.png";
},250);
setTimeout(function()
{
boxOne.src="../Images/p2.png";
},250);
},500);
};
}, 3000);</script>
</head>
<body ng-app="app">
<div class="container" >
<div class="table_set_up_conn">
<div class="set_up_conn">SETTING UP YOUR CONNECTION</div>
</div>
<div class="table_image_anim">
<img id="#image_anim" src="../Images/p1.png"/>
</div>
<div class="grey_layout_anim">
<div class="bold_write"><br>Now let's connect to your Clipsal Hub</div>
<div class="norm_write">1. Go to the Wi-Fi settings on your phone<br><br>2. Connect to the Clipsal Hub network<br><br>3. Return to this app when you're done<br><br></div>
</div>
<div class="table_centre_image">
<img id="#centre_image" src="../Images/p2.png"/>
</div>

</div>
</body>
</html>

错误是

Uncaught TypeError: undefined is not a function .
Function is :getElementsById

最佳答案

首先,它是 getElementById没有s .

其次,你的 JS 代码必须在关闭之前 </body>标签,因为当它现在正在运行时,该元素还不存在。

第三,你有id="#image_anim"这不是有效的身份证件。您想要id="image_anim" 。哈希值 (#) 在 CSS 中用于访问 ID,因此它不能与 ID 名称分开。

关于javascript - getElementById 出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26777943/

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