作者gpmm (银色)
看板Ajax
标题Re: [问题] c转javascript。rand()和Sleep()要怎麽 …
时间Wed Jan 30 17:34:57 2008
※ 引述《demythig (demy)》之铭言:
: 请问我是在哪个地方有写错?
: function setFrame(){
: var x =[];
: x[0]="http://tw.yahoo.com/";
: x[1]="http://www.google.com/";
: x[2]="http://www.pchome.com/";
: var i=Math.round(Math.random()*(x.length-1))
: parent.main.location.href = x[i];
: }
: function main(){
: var loop;
: var randtime;
: document.write("the", "<br>");
: while( loop){
: randtime=Math.random()*2000+3000; //3~5秒
: document.write("sec:", randtime);
: setInterval("setFrame()", randtime);
: }//无限回圈
: }
囧rz
小弟好像讲的不是很正确,如果要喂 rand time ,用 setTimeout 比较合适,
不过 setTimeout 需要一直清触发来缓和记忆体负荷,
var timerID = null;
function setFrame(){
var x =[];
x[0]="
http://tw.yahoo.com/";
x[1]="
http://www.google.com/";
x[2]="
http://www.pchome.com/";
var i=Math.round(Math.random()*(x.length-1))
parent.main.location.href = x[i];
}
function main(){
var randtime = Math.random()*2000+3000; //3~5秒;
document.write("sec:", randtime);
if (timerID) clearTimeout (timerID);
setTimeout ("setFrame()", randtime);
}
至於那个 the 就在找地方输出吧。 :P
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.80.28.216
1F:推 chph:会消失啊 只是停个一两秒吧 01/30 22:28
2F:→ chph:回错.. 01/30 22:28