firefox浏览器不支持innerText的解决方法

时间:2024-04-10 10:51:42 

js代码:


<script>
window.onload = function(){
<PRE class=javascript name="code">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" ? '\n' : childS[i].textContent;
else if(childS[i].nodeType==3)
anyString += childS[i].nodeValue;
}
return anyString;
}
);
HTMLElement.prototype.__defineSetter__( "innerText",
function(sText){
this.textContent=sText;
}
);
};</PRE>var test = document.getElementById("test");<BR>
var innerText_s = test.innerText;<BR>
if( innerText_s == undefined ){<BR>
alert( test.textContent ); // firefox<BR>
}else{ <BR>
alert( test.innerText);<BR>
};<BR>
<BR>
<BR>
}<BR>
<BR>
<BR>
</script><BR>
<PRE></PRE>
<P><BR>
</P>
<P>html代码</P>
<P><div id="test"><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:red">test1</span> test2<BR>
</div><BR>
</P>
标签:firefox,innerText
0
投稿

猜你喜欢

  • win2003 mysql单向同步配置步骤[已测]

    2024-01-14 18:22:16
  • python实现好看的时钟效果

    2021-02-11 23:44:25
  • Python调用graphviz绘制结构化图形网络示例

    2021-09-15 19:06:49
  • asp如何对数组显示和排序?

    2009-11-20 18:30:00
  • pycharm设置python文件模板信息过程图解

    2023-03-21 14:46:22
  • Python subprocess模块详细解读

    2023-11-17 02:50:01
  • 详细解读php的命名空间(二)

    2023-06-06 16:12:38
  • python 利用turtle模块画出没有角的方格

    2022-03-09 04:25:04
  • python中封装token问题

    2022-09-29 01:09:32
  • 使用php shell命令合并图片的代码

    2023-06-21 22:34:35
  • Flask入门教程实例:搭建一个静态博客

    2022-08-12 10:17:38
  • asp如何使用SMTP Service发送邮件?

    2010-06-05 12:43:00
  • 浅谈mysql增加索引不生效的几种情况

    2024-01-25 20:34:43
  • 也谈access数据库的防下载保护

    2007-08-28 13:01:00
  • PHP常用字符串操作函数实例总结(trim、nl2br、addcslashes、uudecode、md5等)

    2023-10-02 13:10:01
  • Mybatis的where标签使用总结梳理

    2024-01-17 01:56:18
  • Go简单实现协程方法

    2024-02-06 05:00:12
  • 微信小程序实现简单倒计时功能

    2024-04-17 10:23:27
  • Python导入父文件夹中模块并读取当前文件夹内的资源

    2023-08-27 09:03:43
  • xhtml+css页面制作过程中问题的解决方案

    2008-08-05 18:00:00
  • asp之家 网络编程 m.aspxhome.com