<!DOCTYPE HTML>
<head>
</head>
<body>
<canvas width="200px" height="200px" id="myCanvas" οnmοusemοve="GetXY(event)" onmoseout="ClearXY()" style="border: 2px solid red;"></canvas>
<script type="text/javascript">
function GetXY(e)
{
x=e.clientX;
y=e.clientY;
document.getElementById("myCanvas").title=""+x + "," + y;
}
function ClearXY()
{
document.getElementById("myCanvas").title="";
}
</script>
</body>
心得:
x,y坐标的起点是左上角 最小值为0