[問題] 網頁沒有更新
要亂數取六個數字,我想設一個按鈕能讓他們一直跑。
我的想法如下:
先在一個大的div內印出六個span;
接著再用getElementByTagName搭配setInterval每0.5秒取代原本的數字;
先在沒有按鈕的情況下用while測試;
但是似乎沒有反應;
不太清楚原因為何?
懇請解釋!
程式碼如如下:
function computeRandom(){
var value = new Array(49);//declare array
for ( i = 0; i < 49; i++ )//initial array_value
value[i] = i+1;
for ( i = 0 ;i < 100; i++ ) {//random arrange
x = parseInt(Math.random()*49);
y = parseInt(Math.random()*49);
tmp = value[x];
value[x] = value[y];
value[y] = tmp;
}
var color = new Array(49);
for ( i = 0; i < 49; i++ )//store color
color[i] = "rgb(" + parseInt(Math.random()*255) + "," +
parseInt(Math.random()*255) + ","
+ parseInt(Math.random()*255) + ")";
var value_tmp = new Array(6);
for( i = 0; i < 6; i++)
value_tmp[i] = value[i];
document.write("<div style = \"text-align:center;\" >");
//center the text by div
for( i = 0; i < 6; i++)
document.write("<span style = \"font-size: 2.5em; display:inline-block;
text-align:center;
width: 1.5em;
background: white;
color: " + color[i] + " \" > " + value_tmp[i]
+ "</span>     ");
var spanArray = document.getElementsByTagName("span");
setInterval("keepMove(value,spanArray)",10);
}
function keepMove(val,sp){
var index = parseInt(Math.random()*43);//set a increment to avoid repeatition
for( i = 0; i < sp.length; i++){
sp[i].innerHTML = val[i+index];
document.write(sp[i].innerHTML+" ");
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.249.13
→
05/21 23:43, , 1F
05/21 23:43, 1F
→
05/22 01:07, , 2F
05/22 01:07, 2F
→
05/22 01:08, , 3F
05/22 01:08, 3F
→
05/22 01:08, , 4F
05/22 01:08, 4F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
問題
0
4