<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>js获取鼠标位置</title>
<style type="text/css">
* {
margin: 0px;
padding: 0px;
}
body{
text-align: center;
height: 1520px;
line-height: 1520px;
border: 1px solid;
font-size: 64px;
}
</style>
</head>
<body id="areaDiv">
<div id="showMasg">
</div>
</body>
<script type="text/javascript">
window.onload = function() {
var areaDiv = document.getElementById("areaDiv");
var showMasg = document.getElementById("showMasg");
areaDiv.onmousemove = function(event) {
var x = event.clientX;
var y = event.clientY;
showMasg.innerText = "X=" + x + ",Y=" + y;
}
}
</script>
</html>