欢迎您访问我爱IT技术网,今天小编为你分享的javascript教程:【firefox浏览器不支持innerText的解决方法】,下面是详细的讲解!
firefox浏览器不支持innerText的解决方法
<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>
关于firefox浏览器不支持innerText的解决方法的用户互动如下:
相关问题:innerText在火狐 失效?????
答:您好!很高兴为您答疑! IE中的获取文本方法是innerText,在firefox中不支持,firefox改成了textContent方法/属性,并且在Firefox中文本中间的空白字符替换了。 您可以在火狐社区了解更多内容。希望我的回答对您有所帮助,如有疑问,欢迎继续在... >>详细
相关问题:JS在火狐下失效怎么解决..
答:打开火狐---工具---选项---内容 在“启动javascript”前面打勾 或者按F12打开FIREBUG,选到“脚本”一项,旁边有个小三角,点开,选择“启用” >>详细
相关问题:火狐浏览器不兼容JS 请高手解决 在线等
答:firefox下面不支持js的innerText ,要把它换成textContent,你改一下试试... >>详细
- 【firefox】firefox浏览器不支持innerText的解决
- 【dom】javascript dom追加内容实现示例-追加内容
- 【checkbox】让checkbox不选中即将选中的checkbox
- 【Array】js中更短的 Array 类型转换-类型转换
- 【append】append和appendTo的区别以及appendChil
- 【ExtJs】ExtJs 表单提交登陆实现代码-表单提交-
- 【addClass】javascript自定义的addClass()方法
- 【Event】jquery下为Event handler传递动态参数的
- 【Ajax】jQuery 学习第六课 实现一个Ajax的TreeVi
- 【cookie】不要在cookie中使用特殊字符的原因分析
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
