作者demythig (demy)
看板Ajax
标题[问题] c转javascript。rand()和Sleep()要怎麽改写?
时间Wed Jan 30 16:00:56 2008
请问以下程式的rand()和Sleep要怎麽改写成javascript?
我想要在conten页对main随机时间(3~5秒)随机网页重新整理。
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <windows.h>
int main(void){
int loop;
int randtime;
srand(time(NULL));
while( loop){
randtime = rand()/100 + 300;
printf("milisec=%d\n", randtime);
setFrame();
Sleep(randtime);//重点是这边~_~请问javascript中类似delay的函数是什麽?
}//无限回圈
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];
}
system("pause");
return 0;
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.225.5.241
※ 编辑: demythig 来自: 61.225.5.241 (01/30 16:07)
※ 编辑: demythig 来自: 61.225.5.241 (01/30 16:08)
1F:→ gpmm:取 rand 用 setInterval 呼叫 setFrome,搞定 :Q 01/30 16:29