源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-10-17 09:08 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:firefox浏览器不支持innerText的解决方法
js代码:
[u]复制代码[/u] 代码如下:
<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>       <span style="color:red">test1</span> test2<BR> </div><BR> </P>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部