什么是IE的removeNode的等价物 [英] What is the equivalent of IE's removeNode

查看:296
本文介绍了什么是IE的removeNode的等价物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IE的removeNode
http:// msdn .microsoft.com / en-us / library / ms536708(VS.85).aspx

IE's removeNode http://msdn.microsoft.com/en-us/library/ms536708(VS.85).aspx

可以帮助我决定是否要删除childNodes不是。

helps me to decide whether I would like to remove childNodes or not.

我想知道是否存在Firefox,Opera,Chrome和Safari。如果没有,我该如何实现呢?

I would like to know whether the same exists for Firefox, Opera, Chrome and Safari. If not, how can I achieve it?

推荐答案

不想只是复制代码, a href =http://www.sitepoint.com/forums//showthread.php?p=947385 =nofollow> http://www.sitepoint.com/forums//showthread.php?p= 947385

Didn't want just just copy code over, give this a read: http://www.sitepoint.com/forums//showthread.php?p=947385

编辑(但我,pst,没有耻辱 - 上面的代码 - - )

Edit (but I, pst, have no shame -- code from above link ;-)

if ( window.Node )
Node.prototype.removeNode = function( removeChildren )
{
    var self = this;
    if ( Boolean( removeChildren ) )
    {
        return this.parentNode.removeChild( self );
    }
    else
    {
        var range = document.createRange();
        range.selectNodeContents( self );
        return this.parentNode.replaceChild( range.extractContents(), self );       
    }
}

这篇关于什么是IE的removeNode的等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆