Javascript:改变img src一段时间后 [英] Javascript : Change img src After some interval of time
本文介绍了Javascript:改变img src一段时间后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
伙计们我不知道如何在javascript中添加一些时间间隔。你知道如何在更改图像的src之前添加一些时间。我从 W3schools 获得此代码
Guys I don't know how to add some interval of time in javascript. Do you know how to add some time before changing src of an image. i get this code from 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>
我已更新你的小提琴
这篇关于Javascript:改变img src一段时间后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文