我正在寫一個腳本,需要在頁面上移動一個包裹節點元素。我發現當我這樣做時,我將先前包裹的孩子刪除。我如何打開一個節點的孩子,以便我可以在其他地方移動父節點?如何在JavaScript中撤消「surroundContents」?
我的想法是這樣的:
var parg = document.getElementById("blah");
if (parg.hasChildNodes())
{
var children = parg.childNodes;
while (children.length > 0)
{
parg.insertBefore(parg.firstChild);
parg.removeChild(parg.firstChild);
};
};
,我猜該生產線的問題了「的insertBefore」的邏輯。
很好的問題!你真的很清楚地表達這個問題 – toddmo 2016-09-07 17:14:44