<script> <br>window.onload = function(){ <br><PRE class=javascript name="code">if(window.navigator.userAgent.toLowerCase().indexOf("msie")==0){ //firefox innerText <br>HTMLElement.prototype.__defineGetter__( "innerText", <br>function(){ <br>var anyString = ""; <br>var childS = this.childNodes; <br>for(var i=0; i<childS.length; i ) { <BR>if(childS[i].nodeType==1) <BR>anyString = childS[i].tagName=="BR" ? 'n' : childS[i].textContent; <BR>else if(childS[i].nodeType==3) <BR>anyString = childS[i].nodeValue; <BR>} <BR>return anyString; <BR>} <BR>); <BR>HTMLElement.prototype.__defineSetter__( "innerText", <BR>function(sText){ <BR>this.textContent=sText; <BR>} <BR>); <BR>};</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