作者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