Javascript下鼠标左键中键右键事件Borwser通用代码支持Firefox

IE和Firefox下Js获取鼠标事件的方式不同,在Annotation Tools项目中,我应用了以下方法为每个动态生成的span对象添加右击删除事件,支持所有浏览器的通用鼠标左键中键右键事件判断代码如下(Firefox&IE下已测试通过): 

      var bowserEvent = [IF IE] ? event : arguments.callee.caller.arguments[0];
       
       if (bowserEvent.which == null)
          /* IE case */
          button= (bowserEvent.button < 2) ? "LEFT" : ((bowserEvent.button == 4) ? "MIDDLE" : "RIGHT");
      else
          /* All others */
          button= (bowserEvent.which < 2) ? "LEFT" : ((bowserEvent.which == 2) ? "MIDDLE" : "RIGHT");
                  
      if (button=="RIGHT") {
             ... ... 
      }

备注:关于事件arguments.callee.caller.arguments[0]详见本站点论坛:使用JS在Firefox与IE中要注意的地方(转载).

引用通告地址: 点击获取引用地址
标签: 脚本
评论: 0 | 引用: 0 | 阅读: 3241 | 打印 | 打包 | 转发
发表评论
昵 称: 密 码:
网 址: 邮 箱:
验证码: 验证码图片 选 项:
头 像:
内 容:
  • 粗体
  • 斜体
  • 下划线
  • 插入图像
  • 超链接
  • 电子邮件
  • 插入引用