帮我看看为什么这样点击事件不弹出坐标
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>onclick</title>
<style type="text/css">
canvas{
border: 2px solid #000;
}
</style>
</head>
<body>
<canvas id="canvas" width="400px" height="400px"></canvas>
</body>
</html>
下面是js代码
var a=document.getElementById('canvas');
var b=a.getContext('2d');
a.onclick=function(e){
var x=e.offsetX;
var i=Math.floor(x);
alert(i);
}