<html>
<head><title>innerHTML</title></head>
<body>
<p id="p1">hello world </p>
<script>
var content = document.getElementById("p1");
alert(content.innerHTML);
alert(content.innerText)
</script>
</body>
</html>
//弹出内容为 "hello world" 和 "hello world"复制代码
<html>
<head><title>innerHTML</title></head>
<body>
<div id="d1"><p id="p1">hello world </p></div>
<script>
var content = document.getElementById("d1");
alert(content.innerHTML);
alert(content.innerText)
</script>
</body>
</html>
//弹出内容为 <p id="p1">hello world </p> 和 hello world复制代码
innerHTML指的是从对象的起始位置到终止位置的全部内容,包括Html标签。
innerText 指的是从起始位置到终止位置的内容,但它去除Html标签
outerHTML指的是除了包含innerHTML的全部内容外, 还包含对象标签本身。