让 FireFox 支持 innerText

Pader 在 2009年8月13日 发表于 网页与编程
  1. function isIE() { //ie? 
  2.     if (window.navigator.userAgent.toLowerCase().indexOf("msie") >= 1) { 
  3.         return true; 
  4.     } else { 
  5.         return false; 
  6.     } 
  7. } 
  8.  
  9. if(!isIE()) { //firefox innerText define 
  10.     HTMLElement.prototype.__defineGetter__("innerText",function(){ 
  11.         var anyString = ""; 
  12.         var childS = this.childNodes; 
  13.         for(var i=0; i < childS.length; i++) { 
  14.             if(childS[i].nodeType==1) { 
  15.                 //anyString += childS[i].tagName=="BR" ? "\n" : childS[i].innerText; 
  16.                 anyString += childS[i].innerText; 
  17.             } else if(childS[i].nodeType==3) { 
  18.                 anyString += childS[i].nodeValue; 
  19.             } 
  20.         } 
  21.         return anyString; 
  22.     }); 
  23.     HTMLElement.prototype.__defineSetter__("innerText",function(sText){ 
  24.         this.textContent=sText; 
  25.     }); 
  26. } 

评论 共有 0 条评论

暂无评论,快发表你的评论吧。