<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
#box{
width: 600px;
height: 600px;
background: pink;
margin-left: 100px;
margin-top: 100px;
position: absolute;
}
</style>
<script type="text/javascript">
window.onload = function(){
var box = document.getElementById("box");
box.onmousemove = function(e){
var e = e || window.event; //判断ie和非ie的获取事件的方法
var left = e.layerX || e.offsetX; //判断是ie和非ie距离事件源的方法
var top = e.layerY || e.offsetY;
document.title = left + '|' + top;
}
}
</script>
</head>
<body>
<div id="box">
</div>
</body>
</html>