例如我有:
<div id="f" style="width:50px; height:50px; background-color:#ddd">
<p>Some text</p>
</div>
我想要<div id="f" style="width:50px; height:50px; background-color:#ddd">
这是我迄今为止尝试过的:
alert(document.getElementById("f").innerHTML);
alert(document.getElementById("f").outerHTML);
和jsfiddle其中。
最佳答案
没有直接的方法可以做到这一点。但是,您可以从outerHTML 内容中删除innerHTML 内容。
document.getElementById("f").outerHTML.replace(document.getElementById("f").innerHTML,'')
关于javascript - 如何获取元素的 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23980598/