鼠标移动事件

一 介绍
鼠标移动事件(onmousemove)是鼠标在页面上进行移动时触发事件处理程序,可以在该事件中用document对象实时读取鼠标在页面中的位置。
 
二 应用
在状态栏中显示鼠标在页面中的当前位置
本示例是鼠标在页面中移动时,在页面的状态栏中显示当前鼠标在页面上的位置,也就是(x, y)值。结果如图7所示。
 
三 代码
<script language="javascript">
<!--
var x=0,y=0;
function MousePlace()
{
 x=window.event.x;
 y=window.event.y;
 window.status="X: "+x+" "+"Y: "+y+" ";
}
document.onmousemove=MousePlace;
//-->
</script>
 
四 运行结果

 

猜你喜欢

转载自cakin24.iteye.com/blog/2356553
今日推荐