ITeye博客

firefox兼容innerText

dragon.dwl · 2010-09-13 10:31 · Web前端 · Markdown

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;
        }
    );
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。