解决firefox不支持innerText的办法
2024-08-31 07:35:47
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" ? '\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;
}
);
};
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>
最新文章
- vs2012 打开解决方案崩溃或者点击项目崩溃
- 通过PHP自带的$_SERVER判断 手机访问网站自动跳转到手机版
- Java_JAVA6动态编译的问题
- Serializable 和 Parcelable 区别
- java.lang.NoClassDefFoundError: javax/transaction/UserTransaction
- Mysql统计同一字段不同值的个数
- scrapy1.1入门用例简介-2
- tomcat的集群配置
- directory not found for option
- js之date()对象
- FPGA实现“打字机”(VGA &; UART)
- 2017-07-12(touch df du)
- jvm内存查看与分析工具
- [USACO12MAR] 花盆Flowerpot
- webpack学习笔记--配置plugins
- [转] babel-plugin-react-css-modules配置
- Java 中的 IO 与 socket 编程 [ 复习 ]
- python多线程学习二
- @Scheduled 定时
- python+selenium六:等待相关