JavaScript:从Array更改iFrame src [英] JavaScript: Change iFrame src from Array
本文介绍了JavaScript:从Array更改iFrame src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我在网页上有一个包含iFrame的3个网址数组。
Say I have an array of 3 URLs with an iFrame on the page.
如何每隔5秒运行这3个网址,然后重新开始?
理想情况下,页面将保持不变,只需更改iFrame src。
How can I run through these 3 URLs every 5 seconds, and then start over? Ideally the page will stay the same, just the iFrame src will change.
推荐答案
这样的事情应该有效:
Something like this should work:
setInterval(function(){
var u = 0;
document.getElementById('myiFrame').setAttribute('src',myUrlArray[u]);
if(u < myUrlArray.length-1){
++u;
}else{
u = 0;
}
},5000);
这篇关于JavaScript:从Array更改iFrame src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文