看板 Ajax 關於我們 聯絡資訊
※ 引述《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
chph:會消失啊 只是停個一兩秒吧 01/30 22:28
chph:回錯.. 01/30 22:28