使用innerHTML的时候将找着元素的内容(不包含元素本身)
使用outerHTML的时候将找着元素的内容(包含元素本身)
innerText,outerText都是返回元素的文本
<html>
<head>
</head>
<body >
<p id="p1">hello world</p>
<script type="text/javascript">
var html=document.getElementById("p1").innerHTML;
console.log('innerHTML:'+html);
var html2=document.getElementById("p1").outerHTML;
console.log('outerHTML:'+html2);
var html3=document.getElementById("p1").innerText;
console.log('innerText:'+html3);
var html4=document.getElementById("p1").outerText;
console.log('outerText:'+html4);
</script>
</body>
</html>
只有outerHTML的表现得比较特别。
outerHTML:<p id="p1">hello world</p>
其他都是以文本格式输出