zoukankan      html  css  js  c++  java
  • JS 获取鼠标坐标

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>JavaScript获取鼠标坐标</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <style type="text/css">
    .tip {
    width:200px;
    border:2px solid #ddd;
    padding:8px;
    background:#f1f1f1;
    color:#666;
    }
    </style>
    <script type="text/javascript"> 
    function mousePos(e){
    var x,y;
    var e = e||window.event;
    return {
    x:e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,
    y:e.clientY+document.body.scrollTop+document.documentElement.scrollTop
    };
    };
    function test(e){
    document.getElementById("mjs").innerHTML = mousePos(e).x+','+mousePos(e).y;    
    };
    </script>
    </head>
    <body>
    <div id="mjs" class="tip">源码爱好者</div>
    <div id="test" style="1000px;height:1000px;background:#ccc;" onmousemove="test(event)"></div>
    </body>
    </html>
    我在IBM工作,可以为大家内部推荐IBM各种职位 IBM全球职位尽在以下链接(请在浏览器中打开,QQ/微信 会阻止): http://ibmreferrals.com/ 很乐意为感兴趣的小伙伴分享:我的面试经验^_^ 如需咨询,请邮件发送以下邮箱,有问必回 1026096425@qq.com
  • 相关阅读:
    全排列问题(递归&非递归&STL函数)
    基于python的机器学习开发环境安装(最简单的初步开发环境)
    X分钟速成Python
    X分钟速成Python3
    Python6
    Python5
    Error[Pe020]: identifier "FILE" is undefined
    串口 ------ 硬件流控
    STM32F103 ------ 时钟配置
    git
  • 原文地址:https://www.cnblogs.com/jackydalong/p/3281130.html
Copyright © 2011-2022 走看看