FF下新增event对象的srcElement、fromElement、toElement三个属性

网摘:

ie下可以直接使用event对象的这三个属性

现在我们需要为FF新增这三个属性:

if(window.addEventListener) { FixPrototypeForGecko(); }  

  function  FixPrototypeForGecko()
  {
      HTMLElement.prototype.__defineGetter__("runtimeStyle",element_prototype_get_runtimeStyle);
      window.constructor.prototype.__defineGetter__("event",window_prototype_get_event);
      Event.prototype.__defineGetter__("srcElement",event_prototype_get_srcElement);
      Event.prototype.__defineGetter__("fromElement",  element_prototype_get_fromElement);
      Event.prototype.__defineGetter__("toElement", element_prototype_get_toElement);

  }  

  function  element_prototype_get_runtimeStyle() { return  this.style; }
  function  window_prototype_get_event() { return  SearchEvent(); }
  function  event_prototype_get_srcElement() { return  this.target; }  

  function element_prototype_get_fromElement() {
      var node;
      if(this.type == "mouseover") node = this.relatedTarget;
      else if (this.type == "mouseout") node = this.target;
      if(!node) return;
      while (node.nodeType != 1)
          node = node.parentNode;
      return node;
  }

  function  element_prototype_get_toElement() {
          var node;
          if(this.type == "mouseout")  node = this.relatedTarget;
          else if (this.type == "mouseover") node = this.target;
          if(!node) return;
          while (node.nodeType != 1)
             node = node.parentNode;
          return node;
  }

  function  SearchEvent()
  {
      if(document.all) return  window.event;  

      func = SearchEvent.caller;  

      while(func!=null){
          var  arg0=func.arguments[0];  

          if(arg0 instanceof Event) {
              return  arg0;
          }
         func=func.caller;</pre><pre class="brush:js">
      }
      return   null;
  }

代码来自于:http://unmi.cc/ie-firefox-event-srcelement-fromelement-toelement

转载于:https://www.cnblogs.com/tatame/archive/2012/11/20/2779027.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值