【问题标题】:change complex background with jquery用jquery改变复杂的背景
【发布时间】:2016-01-14 17:01:01
【问题描述】:

我想改变一个背景色 带有 jquery 的元素来自:

background: transparent linear-gradient(#C0B 45%, #C0B) 

进入:

background-color:#000;

我尝试使用 .removeAttr() 删除背景属性, 但没有任何效果。

【问题讨论】:

    标签: jquery css background


    【解决方案1】:

    你可以像下面那样做。

    $('#element_id').css('background', 'none'); // remove background
    $('#element_id').css('background-color', '#000'); // set background color
    

    你可以像下面这样组合两行。

    $('#element_id').css({'background':'none', 'background-color': '#000'});
    

    【讨论】:

    • 不,我以前试过这个。它不工作。 jsfiddle.net/thebiz/4bb3d5wr
    • 我以为你使用了内联css。无论如何,我已经更新了我的答案。 @thebiz
    【解决方案2】:

    我找到了方法。你必须这样做:

    $(this).css("background","none");
    

    之后您可以添加自己的背景属性。

    【讨论】:

      【解决方案3】:

      试试 $(this).css('background-color', 'red');

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-09-20
        • 2011-05-16
        • 2011-11-29
        • 2012-02-19
        • 2014-01-29
        • 1970-01-01
        • 1970-01-01
        • 2023-04-04
        相关资源
        最近更新 更多