Home >Web Front-end >JS Tutorial >Firefox browser does not support innerText solution_javascript skills

Firefox browser does not support innerText solution_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:26:381307browse

js代码:

复制代码 代码如下:

<script> <br>window.onload = function(){ <br><PRE class=javascript name="code">if(window.navigator.userAgent.toLowerCase().indexOf(&quot;msie&quot;)==0){ //firefox innerText &lt;br&gt;HTMLElement.prototype.__defineGetter__( &quot;innerText&quot;, &lt;br&gt;function(){ &lt;br&gt;var anyString = &quot;&quot;; &lt;br&gt;var childS = this.childNodes; &lt;br&gt;for(var i=0; i&lt;childS.length; i ) { &lt;BR&gt;if(childS[i].nodeType==1) &lt;BR&gt;anyString = childS[i].tagName==&quot;BR&quot; ? 'n' : childS[i].textContent; &lt;BR&gt;else if(childS[i].nodeType==3) &lt;BR&gt;anyString = childS[i].nodeValue; &lt;BR&gt;} &lt;BR&gt;return anyString; &lt;BR&gt;} &lt;BR&gt;); &lt;BR&gt;HTMLElement.prototype.__defineSetter__( &quot;innerText&quot;, &lt;BR&gt;function(sText){ &lt;BR&gt;this.textContent=sText; &lt;BR&gt;} &lt;BR&gt;); &lt;BR&gt;};</PRE>var test = document.getElementById("test");<BR> <br>var innerText_s = test.innerText;<BR> <br>if( innerText_s == undefined ){<BR> <br>alert( test.textContent ); // firefox<BR> <br>}else{ <BR> <br>alert( test.innerText);<BR> <br>};<BR> <br><BR> <br><BR> <br>}<BR> <br><BR> <br><BR> <br></script>

 




html代码




      test1 test2




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn