首页 > Web开发 > 详细

jquery的curCSS方法

时间:2016-10-05 19:49:23      阅读:307      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!