<div id='tbl'> </div>
<script lang="Javascript">
var gd = new Array(16);
var a=0;
for(a=0; a<16; a++)
gd[a] = new Array(16);
var sd = new Array(16);
for(a=0; a<16; a++)
sd[a] = new Array(16);
var b1=0, b2=0;
for(b1=0; b1<16; b1++)
{
for(b2=0; b2<16; b2++)
{
gd[b1][b2]="A";
sd[b1][b2]="A";
}
}
var c1=0, c2=0;
var score=0;
ble = "<center><table>";
for(c1=0; c1<16; c1++)
{
ble += "<tr>";
for(c2=0; c2<16; c2++)
{
ble += "<td onClick='changeColor(this)'>" + gd[c1][c2] + "</td>";
}
ble += "</tr>";
}
ble += "</table></center>";
document.getElementById('tbl').innerHTML = ble;
function changeColor(tdd)
{
if(tdd.bgColor=='white')
{
tdd.bgColor='red';
alert(c1);
/*if (gd[c1][c2] == sd[c1][c2])
score+=5;
else
score-=2;*/
}
else
{
tdd.bgColor='white';
}
}
function scc()
{
document.getElementById('scf').innerHTML = score;
}
</script>
<br><br><center><button type='button' onclick='scc()'> Click to see current score</button> <div id="scf">0</div> </center>
</body>
在上面给出的代码中,有没有办法在 changeColor 函数中获取当前值c1
而c2
不是 =16。
否则,有没有办法写入文档,以免每次都被覆盖?