zoukankan      html  css  js  c++  java
  • JS 获取鼠标位置【转】

    <html>
    <head>
    <script language="javascript" type="text/javascript">
    <!--
    var domType = '';
    if (document.all) {
     domType = "ie4";
    } else if (document.getElementById) {
     domType = "std";
    } else if (document.layers) {
     domType = "ns4";
    }
    function initMouseMove(){
     if(!document.all){
      document.captureEvents(Event.MOUSEMOVE);
     }
     document.onmousemove = mouseMove;
    }
    function mouseMove(e){
     var x,y;
     if(!document.all){
      fetch_object("txt").value="move";
      x=e.pageX;
      y=e.pageY;
     }else{
      x=document.body.scrollLeft+event.clientX;
      y=document.body.scrollTop+event.clientY;
     }
     fetch_object("txt").value=x+":"+y;
    }
    var objects=new Array();

    function fetch_object(idname, forcefetch) {
     if (forcefetch || typeof(objects[idname]) == "undefined") {
      switch (domType) {
       case "std": {
        objects[idname] = document.getElementById(idname);
       }
       break;

       case "ie4": {
        objects[idname] = document.all[idname];
       }
       break;

       case "ns4": {
        objects[idname] = document.layers[idname];
       }
       break;
      }
     }
     return objects[idname];
    }
    -->
    </script>
    <title>get mouse position</title>
    </head>
    <body onload="initMouseMove()">
    <input id="txt"/>
    </body>
    </html>

  • 相关阅读:
    奇怪的人
    假象世界
    心态记录
    民用自组织网络公司概要
    禁止VMware虚拟机与Host的时间同步
    20万左右SUV介绍
    手机GPS为什么能在室内定位?
    取余与位运算
    shell 基础进阶 *金字塔
    shell 、awk两种方法编写9*9法表
  • 原文地址:https://www.cnblogs.com/Godblessyou/p/1779184.html
Copyright © 2011-2022 走看看