伙计们,我不知道如何在 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>
最佳答案
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/