innerHTML 与 innerText的区别

By SuperTaoer | 六月 24, 2010
Under: 程序 技术 周边
Views:

首先,

document.getElementById(‘xxx’).innerHTML 适用于 IE和Firefox浏览器

document.getElementById(‘xxx’).innerText 只适用于IE浏览器

其次:
对于同一个对象,二者返回的内容不一样:
innerHTML 返回的是这个对象内部所有的代码,包括html与非html代码
而innerText只返回这个内部的非html代码。

看个例子:

源代码如下:

页面效果如下:

点击innerHTML的效果:

点击innerText的效果:

差..好文!! (还没评价)
Loading ... Loading ...

Leave a Message

No Messages

No Messages

RSS feed for comments on this post. TrackBack URI

Leave a Message