亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

棋盤點擊不顯示棋子?

棋盤點擊不顯示棋子?

裝狐貍的兔子 2016-06-03 13:15:03
我的代碼里面省略了背景圖、省略了顏色漸變,但是點擊鼠標事件觸發不了?求解釋頁面代碼為:<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");}
查看完整描述

1 回答

?
ThinkAllNight

TA貢獻35條經驗 獲得超31個贊

點擊事件的對象 chess 應該是?document.getElementById('chess');?

而你所獲取對象的變量名是 a ,不是chess 。

查看完整回答
反對 回復 2016-06-19
  • 1 回答
  • 0 關注
  • 1304 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號