六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 50|回复: 0

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

[复制链接]

升级  60%

44

主题

44

主题

44

主题

秀才

Rank: 2

积分
140
 楼主| 发表于 2012-12-22 21:29:23 | 显示全部楼层 |阅读模式
<div id="cnblogs_post_body">网摘:
ie下可以直接使用event对象的这三个属性
现在我们需要为FF新增这三个属性:
<div class="cnblogs_code">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;  }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表