zoukankan      html  css  js  c++  java
  • event的属性

    t获取鼠标相对于浏览器左上角的坐标

     <div id="dv" style=" 300px; height:200px; background-color: Blue;"> 

    <script type="text/javascript">
            window.onload = function () {
                document.getElementById('dv').onmousedown = function () {
                    //相对于页面的左上角0的位置的坐标,不是层的0,0开始
                    if (arguments.length > 0) {
                        //火狐浏览器
                        document.title = arguments[0].clientX + '====' + arguments[0].clientY;
                    } else {
                        //IE浏览器
                        document.title = window.event.clientX + '====' + window.event.clientY;
                    }
                };
            };
        </script>

     获取用户按下的键

     <div id="dv" style=" 300px; height:200px; background-color: Orange;"> 

    <script type="text/javascript">
    
            window.onload = function () {
    
                document.getElementById('dv').onclick = function () {
    
                    //用户是否按下了ctrl键
                    if (window.event.ctrlKey) {
                        alert('按下了ctrl键');
                    } else if (window.event.shiftKey) {
                        alert('按下了shift键');
                    } else if (window.event.altKey) {
                        alert('按下了alt键');
                    } else {
                        alert('什么都没按下');
                    }
                    //用户是否按下了shift键
    
                    //用户是否按下了alt键
                };
              
            };
        </script>

     获取鼠标每个键的值

     window.event.button; //左键是1,右键是2,左右同时是3,中滑轮是4 

     //获取的横坐标是相对屏幕左上角的 // document.title = window.event.screenX+'==='+window.event.screenY;

    //当前这个元素的左上角--事件源 document.title = window.event.offsetX; 

  • 相关阅读:
    添加常驻Notification
    Java 数组操作
    一百本英文原著之旅 ( 15 finished )
    SQLServer2005中查询语句的执行顺序
    高效程序员的45个习惯
    博客园经典闪存语录
    for xml path('') 引发的数据不完整
    ajax向前台输出二维数组 并解析
    重视知识的本质
    C语言排序
  • 原文地址:https://www.cnblogs.com/valiant1882331/p/4071015.html
Copyright © 2011-2022 走看看