jquery的curCSS方法


核心思想是用getComputedStyle獲取樣式,如果沒有獲取到就判斷是不是動態創建的元素,如果是則用style獲取行內樣式。
看重點(注釋部分)代碼吧!

curCSS = function( elem, name ) {
    var ret, 
        computed = window.getComputedStyle( elem, null ),
        style = elem.style;

    if ( computed ) {
        //getPropertyValue兼容ie9獲取filter:Alpha(opacity=50)
        ret = computed.getPropertyValue( name ) || computed[ name ];

        //如果是動態創建的元素,則使用style方法獲取樣式
        if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
            ret = jQuery.style( elem, name );
        }

            
        .................
    }

    return ret;
};

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM