IE中的获取文本方法innerText在firefox中不支持
firefox改成了contentText方法
并且在Firefox中文本中间的空白自符被无情的替换没了      
使用起来异常不方便
现在好了
用Javascript重新定义了innerText方法
使得在Firefox中也可以使用innerText方法
并且此方法解决了firefox中空白字符的问题使用方法:
将下面的脚本放在页面内
不管ie还是firefox都可以使用obj.innerText提取文本了<script   language="javascript">
function   isIE(){   //ie?
      if   (window.navigator.userAgent.toLowerCase().indexOf("msie")> =1)
        return   true;
      else
        return   false;
}if(!isIE()){   //firefox   innerText   define
      HTMLElement.prototype.__defineGetter__(           "innerText",
        function(){
          var   anyString   =   "";
          var   childS   =   this.childNodes;
          for(var   i=0;   i <childS.length;   i++)   {
            if(childS[i].nodeType==1)
              anyString   +=   childS[i].tagName=="BR"   ?   '\n'   :   childS[i].innerText;
            else   if(childS[i].nodeType==3)
              anyString   +=   childS[i].nodeValue;
          }
          return   anyString;
        }
      );
      HTMLElement.prototype.__defineSetter__(           "innerText",
        function(sText){
          this.textContent=sText;
        }
      );
}
</script>也可以用innerHTML

解决方案 »

  1.   

    默认支持innerHTML 其他的如innerText、outerText、outerHTML都不支持
      

  2.   


    <HTML>
    <HEAD>
    <META   http-equiv='Content-Type'   content='text/html;   charset=gb2312'>
    <TITLE> simple  IE only</TITLE>
    </HEAD>
    <BODY   ><div id="aaaa">123asd</div>
    <script   language="javascript"   >
    function   isIE(){ 
    //alert("")
    //alert(window.navigator.userAgent)
    //alert(window.navigator.userAgent.toString().toLowerCase().indexOf("msie"))
          if   (window.navigator.userAgent.toString().toLowerCase().indexOf("msie") >=1)
            return   true;
          else
            return   false;
    }
    //alert(isIE())if(!isIE()){   //firefox   innerText   define
          HTMLElement.prototype.__defineGetter__(           "innerText",
            function(){
              var   anyString   =   "";
              var   childS   =   this.childNodes;
              for(var   i=0;   i <childS.length;   i++)   {
                if(childS[i].nodeType==1)
                  anyString   +=   childS[i].tagName=="BR"   ?   '\n'   :   childS[i].innerText;
                else   if(childS[i].nodeType==3)
                  anyString   +=   childS[i].nodeValue;
              }
              return   anyString;
            }
          );
          HTMLElement.prototype.__defineSetter__(           "innerText",
            function(sText){
              this.textContent=sText;
            }
          ); 

    alert(document.getElementById("aaaa").textContent)
    alert(document.getElementById("aaaa").innerText)
    </script></BODY>
    </HTML>
      

  3.   

    用mingxuan3000铭轩的函数在firefox中应用比较方便,还在类似的event、insertAdjacentHTML等,就可以让firefox支持一些在IE下常用而且很有实用价值功能,以后不用在其它函数再采取判断而实现不同的方法,能统一用IE的方法。