zoukankan      html  css  js  c++  java
  • 鼠标事件兼容

    <body>

    <div class="div1></div>

    </body>

    <script>

    var evetK = {//对象:就相当于苍老师
    //addhandle就相当于苍老师的名字;
     addhandle:function(ele,type,handle){//添加时间
    if (ele.addEventListener) {//只有在谷歌火狐浏览器才满足这个条件
    ele.addEventListener(type, handle, false);
    }else if (ele.attachEvent) {//只有在IE中才满足这个条件
    ele.attachEvent('on'+type,handle);
    }else{
    ele['on'+type] = handle;//如果上述的都不满足执行这个条件
    }
    },
    removehandle:function(ele,type,handle){//移除事件
    if (ele.removeEventListener) {//只有在谷歌火狐浏览器才满足这个条件
    ele.removeEventListener(type, handle, false);
    }else if (ele.detachEvent) {//只有在IE中才满足这个条件
    ele.detachEvent('on'+type,handle);
    }else{
    ele['on'+type] = null;//如果上述的都不满足执行这个条件
    }}}

    evetK.addhandle(div1,'click',test);

    function test(even){
    var a = even||window.event;
    if (a.shiftKey) {
    alert("shift");
    }else if(a.ctrlKey){
    alert("ctrl");
    }else if (a.altKey) {
    alert("alt");
    }
    }

    </script>

  • 相关阅读:
    Java CountDownLatch应用
    servlet 表单
    servlet简单方法
    MySQL WHERE
    JavaScript typeof
    JavaScript字符串
    jsp语法
    HTML链接
    2021.3.10
    2021.3.9
  • 原文地址:https://www.cnblogs.com/a8497336/p/6033837.html
Copyright © 2011-2022 走看看