Document The current browser does not support Canvas, can replace the browser a try! ); ); []; window.onload = function(){ // var canvas = document.getElementById('canvas'); canvas.width = 1024; canvas.height = 768; )){ ){ { x : Math.random()*canvas.width, y : Math.random()*canvas.height, r : Math.random() }; balls[i] = aBall; } draw(); canvas.addEventListener(,detect); }else{ alert(); } } function draw(){ ){ context.beginPath(); context.arc(balls[i].x,balls[i].y,balls[i].r,); context.fillStyle ; context.fill(); } } function detect(event){ canvas.getBoundingClientRect().left; canvas.getBoundingClientRect().top; ){ context.beginPath(); context.arc(balls[i].x,balls[i].y,balls[i].r,); if(context.isPointInPath(x,y)){ context.fillStyle ; context.fill(); } } } 总结 //判断事件是不是在canvas内 context.isPointInPath(x,y)