我想通过从 49 个数字中选择 6 个数字来更改数字,所以首先我声明了一个 div 并在其中有六个跨度来包含一个数字。
我想通过 getElementByTagName 对其进行更改,以分配一个与 setInterval 相结合的新数字,使其始终在更改,但它不起作用。
我错在哪里?
谢谢。
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+" ");
}
}
CSS:
#bg {
background: grey;
opacity: 0.8;
}
#hl {
text-align: center;
color: white;
}
HTML:抱歉,我不知道如何发布 HTML? http://codepad.org/IrSOsjg7
我已经尝试了评论者的建议,但仍然无效,但谢谢您的帮助!我非常感谢!