firefox浏览器不支持innerText的解决方法
firefox浏览器不支持innerText的解决方法
发布时间:2016-12-30 来源:查字典编辑
摘要:js代码:复制代码代码如下:window.onload=function(){if(window.navigator.userAgent.t...

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>

<span>test1</span> test2<BR>

</div><BR>

</P>

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Javascript教程学习
热门Javascript教程学习
编程开发子分类