手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >firefox浏览器不支持innerText的解决方法
firefox浏览器不支持innerText的解决方法
摘要: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>

【firefox浏览器不支持innerText的解决方法】相关文章:

JavaScript实现鼠标滑过处生成气泡的方法

iscroll.js的上拉下拉刷新时无法回弹的解决方法

jQuery取消ajax请求的方法

jQuery fancybox在ie浏览器下无法显示关闭按钮的解决办法

快速判断某个值是否在select中的方法

js去字符串前后空格的实现方法

javascript实时显示当天日期的方法

JavaScript获得url查询参数的方法

JQuery自动触发事件的方法

根据内容自动调整弹出窗口大小的JS解决方案

精品推荐
分类导航