文本替换

<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浏览器不支持。

posted on 2016-12-09 11:54  羽丫头不乖  阅读(157)  评论(0编辑  收藏  举报