English 中文(简体)
删除 儿童真正删除这一内容?
原标题:Does removeChild really delete the element?

? 或者,它只是删除了特定胎盘中的儿童这一元素? 如果它没有真正删除该要素,是否可完全删除该要素?

最佳回答

。 方法只是将其从母体中删除。 如果该网页上有一个可见的内容,该内容将从网页上删除。

But Javascript has garbage collection. This means that the node object itself will remain in existence as long as any variable refers to it. So you can assign a node to a variable, use removeChild to prune it from its parent node, and later on, insert or append it to some other node, thereby effectively moving it around on the page.

下面的法典将删除一条 no子,在把它重新投到树上(从而排到树上)之前等待10秒钟:

var oldNode = someNode.removeChild(...);
setTimeout(function () {
  document.documentElement.appendChild(oldNode);
}, 10000);

这意味着,由于该物体仍然有变数点(即<代码>oldNode),因此该物体没有从记忆中删除。

另一起案件:

var node = document.getElementById( test );
// ... do stuff
node.parentElement.removeChild(node);
//  node  still exists, but has been removed from the page
// ... do some more stuff
node = document.getElementById( hello );
// The variable  node  now points to something else; 
//  this means the original node will be deleted from memory

If, on the other hand, you don’t reassign the removed node to another variable, it can’t be accessed anymore (not via the document tree, since it’s been removed from there; and not via a JS variable); so Javascript will automatically purge it from memory:

someNode.removeChild(...);

将移走的 no子分配到一个变数,然后将<条码>null(或任何其他)分配给这一变量——如马克·布在其答复中建议的那样——是完全不必要的,而且,IMHO是sil的。

问题回答

这将完全删除以下术语:

someNode.removeChild(...);

这将从OMM中清除 no子,使之不明显,但将予以节省,以便你能够在其他地方插入:

oldNode = someNode.removeChild(...);

拆除 孩子们将这个内容从大片中去除,但是如果你重新去做,在别处重新插入,则从该功能中恢复。 你们必须杀死这种回报价值,才能真正摆脱被清除的 no子:

oldNode = someNode.removeChild(...);
oldNode = null;

如果你想要真正删除一个主轴。 拆除 仅靠儿童是不够的。 这与Steveoders的情况一样,后者是Moslow的作者。 您需要删除





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签