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; 

  • 相关阅读:
    2019-9-2-win10-uwp-Markdown
    2018-8-10-控件
    2018-8-10-win10-uwp-dataGrid
    2018-2-13-win10-uwp-hashcash
    2018-2-13-git-cannot-lock-ref
    UCOSIII系统内部任务
    UCOSIII时间片轮转调度
    Keil MDK fromelf生成bin文件
    UCOS内存管理
    uavcan扩展帧格式 zubax
  • 原文地址:https://www.cnblogs.com/valiant1882331/p/4071015.html
Copyright © 2011-2022 走看看