分享

火狐兼容innerText 方法

 文章收藏者 2014-04-14
(function (bool) {
    
function setInnerText(o, s) {
        
while (o.childNodes.length != 0) {
            o.removeChild(o.childNodes[
0]);
        }

        o.appendChild(document.createTextNode(s));
    }

    
function getInnerText(o) {
        
var sRet = "";

        
for (var i = 0; i < o.childNodes.length; i ++) {
            
if (o.childNodes[i].childNodes.length != 0) {
                sRet 
+= getInnerText(o.childNodes[i]);
            }

            
if (o.childNodes[i].nodeValue) {
                
if (o.currentStyle.display == "block") {
                    sRet 
+= o.childNodes[i].nodeValue + "\n";
                } 
else {
                    sRet 
+= o.childNodes[i].nodeValue;
                }
            }
        }

        
return sRet;
    }

    
if (bool) {
        HTMLElement.prototype.__defineGetter__(
"currentStyle"function () {
            
return this.ownerDocument.defaultView.getComputedStyle(thisnull);
        });//FF IE 获取样式兼容

        HTMLElement.prototype.__defineGetter__(
"innerText"function () {
            
return getInnerText(this);
        })

        HTMLElement.prototype.__defineSetter__(
"innerText"function(s) {
            setInnerText(
this, s);
        })
    }
})(
/Firefox/.test(window.navigator.userAgent));
</script>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约