我的代碼里面省略了背景圖、省略了顏色漸變,但是點(diǎn)擊鼠標(biāo)事件觸發(fā)不了?求解釋頁面代碼為:<canvas id="chess" width="450px" height="450px"></canvas>js代碼為:window.onload=function(){ drawchessboard(); drawchess(0,0,true); drawchess(1,1,false);}var a =document.getElementById('chess');var txt=a.getContext('2d');var drawchess=function(i,j,me){ if(me){ txt.fillStyle="#000000"; } else{ txt.fillStyle="#808080"; } txt.beginPath(); txt.arc(15+i*30,15+30*j,15,0,Math.PI*2,true); txt.closePath(); txt.fill();}var drawchessboard=function() { for(var i=0;i<15;i++) { txt.moveTo(15,15+i*30); txt.lineTo(435,15+i*30); txt.moveTo(15+i*30,15); txt.lineTo(15+i*30,435); txt.stroke(); }}chess.onclick=function (e) { var x=offsetX; var y=offsetY; var i=Math.floor(x/30); var j=Math.floor(y/30); drawchess(i,j,true); alert("hello");}
棋盤點(diǎn)擊不顯示棋子?
裝狐貍的兔子
2016-06-03 13:15:03