相关疑难解决方法(0)

jQuery:检查元素是否具有CSS属性

有没有办法检查元素父级并找到第一个具有CSS背景设置然后返回该背景值的方法?

就像是:

var background = $('element').parents().has(css('background'));
Run Code Online (Sandbox Code Playgroud)

更新:这是我现在使用的代码:

jQuery.fn.getBg = function(){
    var newBackground = this.parents().filter(function() {
        return $(this).css('background-color').length > 0;
    }).eq(0).css('background-color');
    $(this).css('background-color',newBackground); console.log("new background is: "+newBackground);
};
Run Code Online (Sandbox Code Playgroud)

jquery

31
推荐指数
3
解决办法
6万
查看次数

标签 统计

jquery ×1