日期:2014-05-16  浏览次数:20352 次

怎么显示鼠标所在的位置?
要求在鼠标后面跟个div,显示:   x和y,(距离左边和顶部的位置)
页面有滚动条,要求这个div一直跟在鼠标后面,而且要显示正确

------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<head>
<meta http-equiv= "content-type " content= "text/html; charset=windows-1250 ">

<title> </title>
<script language=javascript>
window.document.onmousemove=function(){
var o=document.getElementById( "pos ");
o.style.position= "absolute ";
o.style.left=(event.clientX+15)+ "px ";
o.style.top=event.clientY+ "px ";
o.style.border= "2px solid black ";
o.innerHTML= "X= "+event.clientX+ "\n "+ "Y= "+event.clientY;
//alert( event.clientX+ "; "+event.clientY);
}
</script>
</head>
<body>

<div id= "pos "> </div>


</body>
</html>

------解决方案--------------------



路过。。