zoukankan      html  css  js  c++  java
  • 解决firefox不支持innerText的办法

    js代码:
    <script>
    window.onload = function(){
    if(window.navigator.userAgent.toLowerCase().indexOf("msie")==0){ //firefox innerText   
       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" ? '
    ' : childS[i].textContent;  
          else if(childS[i].nodeType==3)  
           anyString += childS[i].nodeValue;  
         }  
         return anyString;  
        }  
       );  
       HTMLElement.prototype.__defineSetter__(     "innerText",  
        function(sText){  
         this.textContent=sText;  
        }  
       );  
    };
    var test = document.getElementById("test");
    var innerText_s = test.innerText;
    if( innerText_s == undefined ){
    alert( test.textContent ); // firefox
    }else{
    alert( test.innerText);
    };


    }


    </script>
    
    


    html代码

    <div id="test">
          <span style="color:red">test1</span> test2
    </div>

  • 相关阅读:
    SQLyog
    远程连接设置
    [转]Oracle/Altibase数据库中Sequence的用法
    worklight 初识
    C# Excel
    C#+AE 叠加分析
    Model Buider中 List和Series的区别[转]
    动态分段
    优化工具箱概述
    创建栅格数据
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3244014.html
Copyright © 2011-2022 走看看