• 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; 

  • 相关阅读:
    whereis which type find
    souce and bash 的区别
    systemctl daemon-reload
    linux /etc/profile bashrc bash_profile
    ulimt 和 sysctl
    MySQL 问题总结
    asyncio
    Linux 中 MySQL 操作
    总结一波 Redis 面试题
    os 模块 和 re 模块
  • 原文地址:https://www.cnblogs.com/valiant1882331/p/4071015.html
Copyright © 2020-2023  润新知