码迷,mamicode.com
首页 > Web开发 > 详细

jquery的curCSS方法

时间:2016-10-05 19:50:09      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

核心思想是用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;
};

 

jquery的curCSS方法

标签:

原文地址:http://www.cnblogs.com/gongshunkai/p/5932551.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!