innerHTML,innerText
文本替換
<p id="p1">Hello World!</p>
<div>神經</div>
<h3 class="hh">天黑了</h3>
<table>
<tr><td name="name">你好</td></tr>
</table>
?
<script>
document.getElementById("p1").innerHTML="已經不是Hello了!";
document.getElementsByName("name")[0].innerText="我不好";
document.getElementsByTagName("div")[0].innerHTML="不是神經";
document.getElementsByClassName("hh")[0].innerText="天亮了";
</script>
PS: ?1、innerHTML是符合W3C標準的屬性,而innerText只適用于IE瀏覽器(現在也適應chrome瀏覽器),因此,盡可能地去使用 innerHTML,而少用innerText
2、innerHTML指的是從對象的起始位置到終止位置的全部內容,包括Html標簽。innerText指的是從起始位置到終止位置的內容,但它去除Html標簽。
3、innerHTML 是所有瀏覽器都支持的,innerText 是IE瀏覽器和chrome 瀏覽器支持的,Firefox瀏覽器不支持。
轉載于:https://www.cnblogs.com/min77/p/6148918.html
總結
以上是生活随笔為你收集整理的innerHTML,innerText的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: kubernetes1.5即将发布
- 下一篇: 初识canvas,使用canvas做一个