• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
小小菜鸟
博客园    首页    新随笔    联系   管理    订阅  订阅
让火狐支持InnerText属性

只需要在页面加载的时候加入下面的代码
 

1.        //让火狐支持innerText   

2.        (function(bool) {   

3.            function setInnerText(o, s) {   

4.                while (o.childNodes.length != 0) {   

5.                    o.removeChild(o.childNodes[0]);   

6.                }   

7.          

8.                o.appendChild(document.createTextNode(s));   

9.            }   

10.       

11.         function getInnerText(o) {   

12.             var sRet = "";   

13.       

14.             for (var i = 0; i < o.childNodes.length; i++) {   

15.                 if (o.childNodes[i].childNodes.length != 0) {   

16.                     sRet += getInnerText(o.childNodes[i]);   

17.                 }   

18.       

19.                 if (o.childNodes[i].nodeValue) {   

20.                     if (o.currentStyle.display == "block") {   

21.                         sRet += o.childNodes[i].nodeValue + ""n";   

22.                     } else {   

23.                         sRet += o.childNodes[i].nodeValue;   

24.                     }   

25.                 }   

26.             }   

27.       

28.             return sRet;   

29.         }   

30.       

31.         if (bool) {   

32.             HTMLElement.prototype.__defineGetter__("currentStyle", function() {   

33.                 return this.ownerDocument.defaultView.getComputedStyle(this, null);   

34.             });   

35.       

36.             HTMLElement.prototype.__defineGetter__("innerText", function() {   

37.                 return getInnerText(this);   

38.             })   

39.       

40.             HTMLElement.prototype.__defineSetter__("innerText", function(s) {   

41.                 setInnerText(this, s);   

42.             })   

43.         }   

44.     })(/Firefox/.test(window.navigator.userAgent));   

 

然后就能使用object.innerText了

posted on 2009-07-22 13:57  service啊啊  阅读(2675)  评论(1)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3