用法: <div id="test"> <span style="color:red">test1</span> test2 </div> 在JS中可以使用:
test.innerHTML
: 也就是从对象的起始位置到终止位置的全部内容,包括Html标签。 上例中的test.innerHTML的值也就是“<span style="color:red">test1</span> test2 ”。
test.innerText:
从起始位置到终止位置的内容, 但它去除Html标签 上例中的text.innerTest的值也就是“test1 test2”, 其中span标签去除了。
test.outerHTML:
除了包含innerHTML的全部内容外, 还包含对象标签本身。 上例中的text.outerHTML的值也就是<div id="test"><span style="color:red">test1</span> test2</div>
完整示例:
<div id="test"> <span style="color:red">test1</span> test2 </div> <a href="javascript:alert(test.innerHTML)">innerHTML内容</a> <a href="javascript:alert(test.innerText)">inerHTML内容</a> <a href="javascript:alert(test.outerHTML)">outerHTML内容</a>
特别说明:
innerHTML是符合W3C标准的属性,而innerText只适用于IE浏览器,因此,尽可能地去使 用innerHTML,而少用innerText,如果要输出不含HTML标签的内容,可以使用innerHTML取得包含HTML标签的内容后,再用正 则表达式去除HTML标签,下面是一个简单的符合W3C标准的示例: <a href="javascript:alert(document.getElementById('test').innerHTML.replace(/<.+?>/gim,''))">无HTML,符合W3C标准</a>
详细解决方案
相关解决方案
- 不同内核浏览器 innerHTML 结果不一样,怎么解决
- a.innerHTML=str innerHTMl比str少了中前期文字
- InnerText 如何用
- document.getElementById("test").innerHTML= 这里内容如何写
- innerHTML 定时插入图片闪烁有关问题
- innerHTML 中p标签的有关问题
- jquery 扩充 outerHTML
- innerHTML、outerHTML、outerText、innerText差异
- 例子innerHtml,innerText,outterHtml,outterText
- js innerhtml 与 creatElement 效率有关问题
- insertRow,innerHTML,写动态平添表格时遇到总结的
- 请们帮忙 InnerHtml 是干什么用的
- innerHTML 异常(转载)
- innerHTML-未知的运行时异常
- innerhtml outerhtml的差异
- innerHTML,innerText,outHTML,outText差异
- innerText innerHtml textContent兼容有关问题(
- js中innerHTML,innerText,outerHTML的用法与差异
- innerHTML、innerText、outerHTML的差别
- Dojo innerHTML 代码不能实施的解决方案
- innerHTML=http.responseText,结果总是一闪而过,咋办?该怎么解决
- DIV.innerHTML=DIV.innerHTML+DIV.innerHTML;后document.getElementById("span").innerText=“晕" 出现重叠解决思路
- innerText 火狐兼容性有关问题
- 为啥 innerHTML 生成的代码,在触发另外一个函数之后就消失了
- innerHTML 怎么加载<option>
- [高分]setAttribute('innerText','5555');的所有替代方法
- 怎么在新打开的窗口中加载object.innerHTML()内的CSS
- javascript string.lastIndexOf不适用于span innerHTML
- innerText 和 innerHTML的区别
- JS基础—innerHTML