1.图片效果
2.代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
#box1{
width: 300px;
height: 300px;
background-color: #FFFF00;
margin: 10px;
}
#box2{
width: 300px;
height: 100px;
margin: 10px;
border-style: solid;
border-color: #0000FF;
}
</style>
</head>
<body>
<div id="box1">
</div>
<div id="box2">
</div>
<script type="text/javascript">
var box1= document.getElementById("box1");
var box2 = document.getElementById("box2");
box1.onmousemove = function(event){
if(!event){
event = window.event;
}
event = event || window.event;
var xp = event.clientX;
var yp = event.clientY;
box2.innerHTML = "x坐标:"+xp+"\ty坐标"+yp;
}
</script>
</body>
</html>