1.innerHTML
innerHTML可获取或设置指定元素标签内的 html内容,从该元素标签的起始位置到终止位置的全部内容(包含html标签)。
获取元素的内容:element.innerHTML;
给元素设置内容:element.innerHTML =htmlString;
代码示例为:
<p id="test"><font color="#000">获取段落p的 innerHTML</font></p>
document.getElementById("test").innerHTML
输出内容为:<font color="#000">获取段落p的 innerHTML</font>
javascript获取节点文本值:
(1)原生js写法 document.getElementById(‘test’).innerHTML
(2)jQuery写法 $(’#test’).html()
outerHTML:
除了包含innerHTML的全部内容外, 还包含对象标签本身。
<div id="test">
<span style="color:red">test1</span> test2
</div>
//test.innerHTML
“<span style="color:red">test1</span> test2 ”
//text.outerHTML
<div id="test"><span style&