这是我电脑的问题吗。
var me = true;
var chessBorad = [];
for (var i = 0; i < 15; i++) {
chessBorad[i] = [];
for (var j = 0; j < 15; j++) {
chessBorad[i][j] = 0;
}
}
var chess = document.getElementById('chess');
var context = chess.getContext('2d');
context.strokeStyle = "#eee";
var logo = new Image();
logo.src = './image/beijing.png';
logo.onload = function() {
context.drawImage(logo, 0, 0, 450, 450);
drawLine();
oneStep(1, 1, true);
oneStep(2, 2, false);
}
function drawLine() {
for (var i = 0; i < 15; i++) {
context.moveTo(15 + i * 30, 15);
context.lineTo(15 + i * 30, 435);
context.stroke();
context.moveTo(15, 15 + i * 30);
context.lineTo(435, 15 + i * 30);
context.stroke();
}
}
var oneStep = function(i, j, me) {
context.beginPath();
context.arc(15 + i * 30, 15 + 30 * j, 12, 0, 2 * Math.PI);
context.closePath();
var gradient = context.createRadialGradient(15 + i * 30 + 2, 15 + 30 * j - 2, 8, 15 + i * 30 + 2, 15 + 30 * j - 2, 5);
if (me) {
gradient.addColorStop(0, '#000');
gradient.addColorStop(1, '#ddd');
} else {
gradient.addColorStop(0, '#ddd');
gradient.addColorStop(1, '#fff');
}
context.fillStyle = gradient;
context.fill();
}
chess.onclick = function(e) {
var x = e.offsetX;
var y = e.offsetY;
var objX = Math.floor(x / 30);
var objY = Math.floor(y / 30);
if ( chessBorad[i][j] == 0) {
oneStep(objX, objY, me);
if (me) {
chessBorad[i][j] = 1;
} else {
chessBorad[i][j] = 2;
}
}
me = !me;
}
为什么一直提示qizi.js:57 Uncaught TypeError: Cannot read property '15' of undefined,有人遇到过吗?或者把你们的代码发出来给我参考下