【问题标题】:Member not found IE error (IE 6, 7, 8, 9)找不到成员 IE 错误(IE 6、7、8、9)
【发布时间】:2011-04-01 16:45:38
【问题描述】:

让我首先向任何 IE 用户指出(这在 Chrome、Safari 或 Firefox 中不是问题)提示提示;)

所以...我在 IE 中的工具提示有问题,我有一个 onmouseover 侦听器,用于所有要悬停的元素,然后在我的 mouseover 函数中,我有一个非常基本的跨浏览器声明......

var event = e || window.event,
    el = event.target || event.srcElement;

我遇到了 IE 中不存在的窗口对象或其他东西的问题,在我添加了一个标志以忽略从一个元素鼠标悬停到工具提示本身的过程中的鼠标悬停之后(在允许的时间周期内) , 300 毫秒)。换句话说,标志是忽略从原始鼠标悬停到工具提示的路径上的鼠标悬停。

所以逻辑看起来像这样......

loadtip.refMouseOver = function (e) {

    var event = e || window.event, el = event.target || event.srcElement;
    //console.log(window); // <-- throws error in IE (Member not found)
    // Reset the lastHoveredRef data.
    tipManager.lastHoveredRef = null;
    tipManager.lastHoveredRef = [el, event];

    // true means there is a tip open still, so if no tip is open.
    if (tipManager.tipState !== true) { 
        tipManager.processTip(el, event);
    } else {        
        return; // do nothing
    }

}

当我在 IE 中快速从一个元素悬停到下一个元素且工具提示仍处于打开状态时,将出现“未找到成员”错误。

我通过 try catch 阅读了有关 window.open 和 close 的内容,但我没有看到它是如何相关的。非常感谢任何帮助。

谢谢

【问题讨论】:

    标签: internet-explorer javascript-events


    【解决方案1】:

    好的,我找到了问题。

    总而言之,如果函数调用在 setTimeout 内,则基本上 IE 不会将事件传递给另一个函数。

    因此,您可以通过创建事件副本并传递它来欺骗 IE,这是一个示例......

    var eventCopy = {};
    for (var i in event) {
        eventCopy[i] = event[i];    
    }
    

    然后只需将 eventCopy 发送给您的函数,即使这是“完全”的黑客攻击。

    setTimeout(function () { yourFunction(eventCopy), yourDelayTime);
    

    瞧,它会起作用的。

    我应该补充一点,Internet Explorer 只会创建对全局窗口事件的引用,这就是我们需要事件副本的原因。这是因为到 setTimeout 调用函数的时候,windows.event 已经过去了,

    底线...不要尝试在 setTimeout 内发送事件,因为 IE 不会接受它。从我的测试来看,对于 IE 6、7 和 8 来说都是如此。

    【讨论】:

      【解决方案2】:

      我意识到这个问题/答案已经很老了,似乎已经解决了。话虽如此,我还有另一个替代方案,我曾经在 MSIE 9 之前的 IE 版本中处理过类似但略有不同的“未找到成员”问题。我希望这对某人有所帮助! ...这也可以用来解决 Firefox 没有 window.event 的问题。

      首先我扩展了 jQuery 并添加了一个函数来获取 MSIE 版本,如果浏览器不是 MSIE,则为 -1。您可以执行相同的操作,也可以创建一个纯 JS 函数来完成此操作。然后创建一个事件覆盖函数(在某些情况下可能需要添加一个全局“事件”变量),这更多是针对每个具体情况。然后根据需要覆盖事件处理程序中的事件。

      扩展 jQuery

      // So this will give you the version of IE (or for non IE browser -1)
      $.fn.msieVersion = function()
      {
          if ( navigator.userAgent.toLowerCase().indexOf( 'msie' ) !== -1 ) {
              return document.documentMode; 
          }
          return -1;
      };
      

      覆盖全局事件

      var setEvent = function( evt ) {
          // Set the event if MSIE version is >= 9 or is -1 which means it's not IE
          if ( $.fn.msieVersion() >= 9 || $.fn.msieVersion === -1 ) { 
              // NOTE: I have a global 'event' variable I'm using that comes from another previously loaded JS file 
              // Why? I didn't do it. I'm updating some SUPER old code the best I can. (old enough it has references to Netscape....)
              event = evt || window.event; 
          }
          return true;
      };
      

      使用示例

      $( 'img.myImageID' ).bind('mouseover mouseout', function ( evt ) {
          setEvent( evt ); // Override the event
          // DO WORK! ...continue all other awesomeness here!
          // Maybe setTimeout(...)
      };
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-14
        • 1970-01-01
        • 2013-12-23
        • 2014-11-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多