JS的innerText和textCont

innerText设置元素内部的普通文本即使是html代码也只是当做普通文本处理,
chrom和IE支持,低版本FF不支持
TextContext也是当做普通文本 chrom浏览器和FF支持,IE不支持
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JSDom获取图层节点</title>
</head>
<body>
<script type="text/javascript">

function getInnerText() {
var myDiv=document.getElementById("myDiv");
var info=navigator.userAgent.toLowerCase();
if(info.indexOf("firefox")){
myDiv.textContent="<h1><font>这是textContent</font></h1>";
}else{
myDiv.innerText="<h1><font color='red'>这是innerText</font></h1>";

}

}
</script>

<input type="button" value="测试" onclick="getInnerText()">
<div id="myDiv"></div>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/god1/p/12115069.html