jjzjj

childDiv

全部标签

javascript - 在不知道其父元素的情况下删除 dom 元素?

是否可以删除除body标签外没有父元素的dom元素?我知道使用像jquery这样的框架会很容易,但我试图坚持直接使用javascript。这是我发现的其他代码:functionremoveElement(parentDiv,childDiv){if(childDiv==parentDiv){alert("Theparentdivcannotberemoved.");}elseif(document.getElementById(childDiv)){varchild=document.getElementById(childDiv);varparent=document.getElem

javascript - 在不知道其父元素的情况下删除 dom 元素?

是否可以删除除body标签外没有父元素的dom元素?我知道使用像jquery这样的框架会很容易,但我试图坚持直接使用javascript。这是我发现的其他代码:functionremoveElement(parentDiv,childDiv){if(childDiv==parentDiv){alert("Theparentdivcannotberemoved.");}elseif(document.getElementById(childDiv)){varchild=document.getElementById(childDiv);varparent=document.getElem