代码描述:javascript兼容 火狐等浏览器 innerText属性。javascript兼容火狐等浏览器innerText属性源码下载
关于innerText属性的基本用法可以参阅javascript innerText属性用法一章节。 因为存在兼容问题,下面就通过代码实例介绍一下如何模拟实现各个浏览器的兼容效果。 代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="https://www.51qianduan.com/" /> <title>51前端</title> <style type="text/css"> #antzone{ width:300px; height:100px; text-align:center; line-height:100px; background-color:#CCC; } </style> <script type="text/javascript"> function isIE(){ if (window.navigator.userAgent.toLowerCase().indexOf("msie")>=1){ return true; } else{ return false; } } if(!isIE()){ 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; }); } window.onload=function(){ var odiv=document.getElementById("antzone"); var obt=document.getElementById("bt"); obt.onclick=function(){ odiv.innerText="<strong>51前端</strong>"; } } </script> </head> <body> <div id="antzone"></div> <input type="button" id="bt" value="查看效果"/> </body> </html>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能