2010-12-10 65 views
0

我需要设置约1秒的时间间隔,这样的功能:的setInterval的随机函数

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" 

    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() 

请SMB帮助!

回答

0

如果你想一次调用的函数,然后使用 “的setTimeout”。如果你想持续调用的函数,然后使用“setInterval的”

e.g

var intervalID = setInterval("random_imglink()", 1000); 

注:然后您可以停止功能通过使用被称为:

clearInterval(intervalID); 
1

容易:

setTimeout("javascript statement",milliseconds); 
0
var random_imglink = function(){ 
    // [...] 
} 
setTimeout(random_imglink, 1000 )