Firefox textContent属性等效于IE的innerText

  在IE和Opera下,DOM对象支持innerText属性,可以很方便的去除HTML标签。

  但在Firefox不支持该属性,FF下的DOM对象支持textContent,该属性与IE浏览器的innerText属性等效。

  示例:
+展开
-HTML
<p id="TestObj">Hi,I'm <strong>cnlei</strong>.Welcome to my homepage:<a href="http://www.cnlei.com">http://www.cnlei.com</a>.</p>
<script type="text/javascript">
function getInnerText(obj){
return document.all?obj.innerText:obj.textContent;
}
var str = getInnerText(document.getElementById("TestObj"));
alert(str);
</script> 

加支付宝好友偷能量挖...


评论(0)网络
阅读(94)喜欢(0)JavaScript/Ajax开发技巧