<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>程彩虹</title>
<style>
#firdiv{
width: 80px;
height: 20px;
background-color: aqua;
display: none;
position: absolute;
top: 0px;
left: 0px;
font-size: 12px;
}
</style>
</head>
<body>
<div id="firdiv">
<span id="firspan"></span>
</div>
<script>
var x=0,y=0;
function fun(){
//获取鼠标位置
x=window.event.x;
y=window.event.y;
//显示
var span=document.getElementById('firspan');
span.innerText="X:"+x+","+"Y:"+y;
span.style.fontSize='12px';
span.style.paddingLeft='6px';
//移动框
var fir=document.getElementById('firdiv');
fir.style.display='block';
fir.style.top=y+'px';
fir.style.left=x+'px';
}
document.onmousemove=fun;
</script>
</body>
</html>