firefox瀏覽器不支持innerText的解決方法
更新時(shí)間:2013年08月07日 15:25:25 作者:
在測(cè)試時(shí)發(fā)現(xiàn)firefox不支持innerText,該怎么辦呢?其實(shí)很簡(jiǎn)單,本文為大家提供了一個(gè)解決方法,感興趣的朋友可以參考下,希望對(duì)大家有所幫助
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 style="color:red">test1</span> test2<BR>
</div><BR>
</P>
復(fù)制代碼 代碼如下:
<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>
相關(guān)文章
JS實(shí)現(xiàn)頁(yè)面打?。ㄕw、局部)
本篇文章主要介紹了JS實(shí)現(xiàn)頁(yè)面打印(整體、局部),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-08-08webpack.DefinePlugin與cross-env區(qū)別詳解
這篇文章主要介紹了webpack.DefinePlugin與cross-env區(qū)別詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02教你javascript如何獲取對(duì)象的key和value
獲取對(duì)象所有key的方法,需要使用?Object.keys(obj)?方法,Object.keys(obj)方返回一個(gè)數(shù)組,這個(gè)數(shù)組包含obj對(duì)象中的所有key,這篇文章主要介紹了javascript如何獲取對(duì)象的key和value,需要的朋友可以參考下2022-12-12微信小程序?qū)崿F(xiàn)拍照和相冊(cè)選取圖片
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)拍照和相冊(cè)選取圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-05-05Textbox控件注冊(cè)回車事件及觸發(fā)按鈕提交事件具體實(shí)現(xiàn)
Lyncplus客戶端中訪問(wèn)Web頁(yè)面時(shí)遇到了TextBox控件回車自動(dòng)完成按鈕的提交事件失效的情況,于是上網(wǎng)查找相關(guān)的介紹最終解決了這兩個(gè)問(wèn)題,感興趣的你可以參考下或許對(duì)你有所幫助2013-03-03js實(shí)現(xiàn)指定時(shí)間倒計(jì)時(shí)效果
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)指定時(shí)間倒計(jì)時(shí)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-08-08Laydate時(shí)間組件在火狐瀏覽器下有多時(shí)間輸入框時(shí)只能給第一個(gè)輸入框賦值的解決方法
這篇文章主要介紹了Laydate時(shí)間組件在火狐瀏覽器下有多時(shí)間輸入框時(shí)只能給第一個(gè)輸入框賦值的解決方法,需要的朋友可以參考下2016-08-08