欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

讓innerText在firefox火狐和IE瀏覽器都能用的寫(xiě)法

 更新時(shí)間:2011年05月14日 15:24:44   作者:  
下面的代碼主要是用來(lái)解決firefox瀏覽器不支持innerText的問(wèn)題,需要的朋友可以參考下。
IE中的獲取文本方法innerText在firefox中不支持
firefox改成了textContent方法/屬性

并且在Firefox中文本中間的空白自符被無(wú)情的替換沒(méi)了
使用起來(lái)異常不方便
現(xiàn)在好了,用Javascript重新定義了innerText方法
使得在Firefox中也可以使用innerText方法
并且此方法解決了firefox中空白字符的問(wèn)題

使用方法:
將下面的腳本放在頁(yè)面內(nèi)
不管ie還是firefox都可以使用obj.innerText提取文本了
復(fù)制代碼 代碼如下:

<script language=”javascript”>
function isIE(){ //ie?
if (window.navigator.userAgent.toLowerCase().indexOf(“msie”)>=1)
return true;
else
return false;
}
if(!isIE()){ //firefox innerText define
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;
}
);
}
</script>

相關(guān)文章

最新評(píng)論