在这段代码中,我加载了一些骰子的图像,并尝试在表格中显示其中的一些。我不确定我是否正确构建了数组,但这是我发现的使用图像传播数组的示例之一。
<table id="dicebox">
<tr>
<td id="d1"></td>
<td id="d2"></td>
<td id="d3"></td>
<td id="d4"></td>
<td id="d5"></td>
</tr>
</table>
<script>
var diceB = new Array(7);
//Blue dice
var diceP = new Array(7);
//Purple dice
var diceValue = new Array(0, 1, 2, 3, 4, 5, 6);
//initializing blue dice array
diceB[0] = new Image(50, 50);
diceB[0].src = "images/dice0B.gif"
diceB[1] = new Image(50, 50);
diceB[1].src = "images/dice1B.gif"
diceB[2] = new Image(50, 50);
diceB[2].src = "images/dice2B.gif"
diceB[3] = new Image(50, 50);
diceB[3].src = "images/dice3B.gif"
diceB[4] = new Image(50, 50);
diceB[4].src = "images/dice4B.gif"
diceB[5] = new Image(50, 50);
diceB[5].src = "images/dice5B.gif"
diceB[6] = new Image(50, 50);
diceB[6].src = "images/dice6B.gif"
for(var i = 1; i < 6; i++) {
document.getElementById('d' + i).innerHTML = diceB[i].src;