如何为随机图像变化设置时间间隔

发布于 2024-10-06 16:54:17 字数 842 浏览 0 评论 0原文

我想设置一个间隔,这样它每次都会从这个函数生成一个随机链接:

function random_imglink(){
    var myimages=new Array()
    //specify random images below. You can have as many as you wish
    myimages[1]="/documents/templates/bilgiteknolojileri/standalone.swf"
    myimages[2]="/documents/templates/bilgiteknolojileri/mobil.swf"
    myimages[3]="/documents/templates/bilgiteknolojileri/3b2.swf"

    var ry=Math.floor(Math.random()*myimages.length)

    if (ry==0)
    ry=1
    document.write('<embed wmode="transparent" src="'+myimages[ry]+'" height="253" width="440"></embed>')
  }
  random_imglink()

但问题是,在我将超时集成到这样的函数中后

  random_imglink()
  setInterval( "random_imglink()", 2000 );

,2秒后它只显示嵌入对象,我的意思是唯一的页面上显示的东西是嵌入对象,仅此而已......再过 2 秒后,它不会更改该对象......我想要的只是更改嵌入对象内的链接,这样它就不会阻止页面视觉,请帮助我!

i want to put an interval ,so that it will generate each time a random link from this function:

function random_imglink(){
    var myimages=new Array()
    //specify random images below. You can have as many as you wish
    myimages[1]="/documents/templates/bilgiteknolojileri/standalone.swf"
    myimages[2]="/documents/templates/bilgiteknolojileri/mobil.swf"
    myimages[3]="/documents/templates/bilgiteknolojileri/3b2.swf"

    var ry=Math.floor(Math.random()*myimages.length)

    if (ry==0)
    ry=1
    document.write('<embed wmode="transparent" src="'+myimages[ry]+'" height="253" width="440"></embed>')
  }
  random_imglink()

but the problem is that after i integrate the timeout to a func like this

  random_imglink()
  setInterval( "random_imglink()", 2000 );

after 2 sec it shows just the embed object, i mean the only thing that displayed on the page is the embed object, thats all.. and after another 2 sec it doesn't change the object... all i want is to change just the link inside the embed object, so that it wont brake the page vision, please help me!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜唯美灬不弃 2024-10-13 16:54:17

您不应该在超时时写入嵌入对象,而应该在那里覆盖它。

将嵌入对象直接添加到 HTML 中:

<embed id="randomEmbed" ...other parameters...></embed>

然后在计时器函数中将写入更改为如下所示:

document.getElementById("randomEmbed").src = myimages[ry];

You should not write the embed object in timeout but overwrite it there.

Add the embed object directly into your HTML:

<embed id="randomEmbed" ...other parameters...></embed>

Then in your timer function change the writing to something like this:

document.getElementById("randomEmbed").src = myimages[ry];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文