ITeye博客

firefox不支持innerText

dzt · 2010-01-06 10:07 · javascript · Web前端 · Markdown

firefox不支持innerText

 近来写javascript 发现innerText在 firefox上是不支持的。但IE和FF都支持innerHTML,

怎样解决firefox支持innerText,我找一些资料发现原来FF有一个方法,类似innerText的功能,

这就是textContent了,但textContent会自动去除掉多余的空格,就这点有所不同外,基本是

与innertText相同的。这个是我的见解,如有不对之处,可以大家讨论一下。

 例子:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns="http://www.w3.org/1999/xhtml " >
<head>
    <title>Untitled Page</title>
</head>
<body>
<div id="aa" >sdfasdfsd</div>
</body>
</html>
<script type ="text/javascript" >

var isie=document.all?true:false;
if(isie)
{
    var dd=document.getElementById('aa').innerText;
    alert(dd);
}
else
{
     var dd=document.getElementById('aa').textContent;
    alert(dd);
}

</script>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。