gpt4 book ai didi

JavaScript : Change img src After some interval of time

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

伙计们,我不知道如何在 JavaScript 中添加一些时间间隔。您知道如何在更改图像的 src 之前添加一些时间吗?我从 W3schools 获取此代码

document.getElementById("image").src = "http://www.w3schools.com/js/landscape.jpg";
<!DOCTYPE html>
<html>
<body>

<img id="image" src="http://www.w3schools.com/js/smiley.gif" width="160" height="120">

<p>The original image was smiley.gif, but the script changed it to landscape.jpg</p>

</body>
</html>

JsFiddle

最佳答案

setTimeout(function() {
document.getElementById("image").setAttribute("src", "http://www.w3schools.com/js/landscape.jpg");
}, 5000);
<img id="image" src="http://www.w3schools.com/js/smiley.gif" width="160" height="120">

<p>The original image was smiley.gif, but the script changed it to landscape.jpg</p>

我已经更新了您的fiddle

关于JavaScript : Change img src After some interval of time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31409311/

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