【问题标题】:IE8 and IE9 compatible statement for el.nextSibling.contains(e.target)el.nextSibling.contains(e.target) 的 IE8 和 IE9 兼容声明
【发布时间】:2015-12-11 02:08:33
【问题描述】:

我正在寻找 if (! el.nextSibling.contains(e.target) ) 的类似物,不确定有什么 jQuery 替代品可以工作并且支持 IE8 和 IE9

我已经尝试过$.contains($(el).next(), e.target) 和变体,但我碰壁了。有什么建议吗?

编辑 - 在这种情况下的事件是点击:

document.addEventListener('click', function(e) {
  [].forEach.call(myMenu.open, function(el) {
    el.addEventListener('click', function(e) {
        myMenu.activate(e);
    }, false);
  });
}

...

'activate': function(e) {
    e.preventDefault();

    var open = document.querySelectorAll('.slide');


    [].forEach.call(open, function(el) {
      if (!el.nextElementSibling.contains(e.target) && el != e.target) {
        console.log('Do something');
      }
    }
}

第二次更新: 我现在以不同的方式处理这个问题 - 我能够引用 parentNode 并实现我想要的相同效果,这在 IE8 和 IE9 中受支持。例如:

if (!el.parentNode.contains(e.target) && el != e.target) {

感谢您的帮助!

【问题讨论】:

  • 那么你如何获得事件对象呢?包装这个语句的代码是什么?有错误信息吗?
  • 事件对象被传递到函数中。给你一个想法,这段代码适用于 IE10+、Chrome、Safari、Firefox 等,但不适用于 IE9 和 IE8,因为它们对 JS 的限制: if (!el.nextElementSibling.contains(e.target) && el != e.target) {
  • 这篇文章对你有帮助吗,在你的情况下:ericleads.com/2013/10/javascript-string-contains ?

标签: javascript jquery internet-explorer-8 internet-explorer-9


【解决方案1】:
if (!el.parentNode.contains(e.target) && el != e.target) {

适用于我的情况,受 IE8 和 IE9 支持

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    • 2012-05-29
    • 1970-01-01
    相关资源
    最近更新 更多