使用jQuery一次显示一个iframe中的链接列表 [英] Show a list of links in an iframe one at a time with jquery
问题描述
好吧,所以我需要一个脚本帮助,该脚本获取数组中的网址列表,然后在iframe中一次显示每个网址,并允许我在指向下一个网址的链接周围加边框在iframe中列出.我需要它显示该页面大约3秒钟,然后显示下一页以及下一页,依此类推,但一次只显示一页.
Ok, so I need help with a script that takes a list of urls in an array, then shows each url one at a time in an iframe, and allows me to put a border around the link to the next item of the list INSIDE the iframe. I need it to show the page for about 3 seconds, then display the next page, and the next and so on, but only one page at a time.
到目前为止,我在这里:
Here's where I'm at so far:
var links = ["link1", "link2", "link3"];
for (var i = 0; i < links.length; i++)
{
$("#viewer iframe")
.attr('src', "http://www.mysite.com/" + links[i])
.load(function() {
$(this).contents().find("a[href*='" + links[i+1] + "']").css("border", "1px solid black");});
setTimeout('$("#viewer iframe").attr("src", "")', 3000);
}
这可以显示数组中的第一个链接,然后在3秒钟后将iframe src设置为空,但不会显示后续链接.
This works to show the first link in the array and then after 3 seconds sets the iframe src to nothing, but it doesn't show the subsequent links.
推荐答案
尝试一下:
var links = ["link1", "link2", "link3"];
var current = 0;
function showNextLink()
{
if (current >= links.length) {
return;
}
$("#viewer iframe")
.attr('src', "http://www.mysite.com/" + links[current])
.load(function() {
if (current < links.length) {
$(this).contents().find("a[href*='" + links[current+1] + "']").css("border", "1px solid black");}});
current++;
setTimeout(arguments.callee, 3000);
}
showNextLink();
这篇关于使用jQuery一次显示一个iframe中的链接列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!