【问题标题】:DOMNodeInserted in the IE在 IE 中插入 DOMNode
【发布时间】:2013-09-16 02:53:10
【问题描述】:

为什么这段代码在 IE 中不起作用?请帮忙解决:

jQuery('body').live('DOMNodeInserted',function(e){
    var parent = jQuery(e.target).parent();
    parent.find("a").css('color','#AA62C6');
    parent.find('a').removeAttr('onmousedown');
});

【问题讨论】:

    标签: jquery internet-explorer cross-browser dom-manipulation mutation-events


    【解决方案1】:

    IE 不支持此事件。这已添加到 IE9,但在实现中似乎存在错误。

    解决方案是在基础(更改 dom 的方法)级别处理 dom 操作。

    function update(){
        //do some dom manipulation
        $(window).trigger('customupdatedom', parent);
    }
    $(window).on('customupdatedom', function(e, parent){
        //handle dom change
    })
    

    您还可以阅读以下内容
    DOMNodeInserted equivalent in IE?
    DOMNodeInserted event

    【讨论】:

    • 感谢您的帮助,但是当我尝试将其应用于我的麻烦时,它仍然不起作用。
    • 我想在页面加载之前更改 'a' css 参数。 css导入有两个html链接标签..
    【解决方案2】:

    在 IE 中使用 onreadystatechange

    var parent;
    
    if (!!document.addEventListener)
      {
      jQuery('body').live('DOMNodeInserted',function(e){
        parent = jQuery(e.target).parent();
        parent.find("a").css('color','#AA62C6');
        parent.find('a').removeAttr('onmousedown');
        });
      }
    else
      {
      jQuery("body").get(0).addBehavior("foo.htc");
      jQuery('body').get(0).attachEvent('onreadystatechange',function(e){
        parent = jQuery(e.target).parent();
        parent.find("a").css('color','#AA62C6');
        parent.find('a').removeAttr('onmousedown');
        });  
      }
    

    【讨论】:

      猜你喜欢
      • 2011-05-23
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      • 1970-01-01
      • 1970-01-01
      • 2011-06-05
      • 2011-05-29
      相关资源
      最近更新 更多