获取鼠标所在的坐标实例

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 <script>
 function test(){
    //var huoqu=document.getElementById("huoqu");
    huoqu.innerText="x="+event.clientX+"y="+event.clientY;//clien是针对当前窗口
    huoqu2.innerText="x="+event.screenX+"y="+event.screenY;//clien是针对当前屏幕
    }
 </script>
 </HEAD>

 <BODY>
  <div onmousemove="test()" style="width:400px;height:300px;border:1px red solid">
  </div>
  <span id="huoqu"></span><br/>
  <span id="huoqu2"></span>
 </BODY>
</HTML>

 

posted @ 2015-04-16 10:13  绝版幸福  阅读(803)  评论(0编辑  收藏  举报