【问题标题】:Remove a specific inline style value with jQuery.使用 jQuery 删除特定的内联样式值。
【发布时间】:2013-03-25 14:38:35
【问题描述】:

我想从任何可能出现的标签中删除特定的内联颜色样式。颜色的样式为 style="color: rgb(255, 102, 0);"。

我正在尝试仅使用 a 标签进行测试,但并没有走得太远。想法?不是 Jquery 人,所以我需要很多帮助:)。

    $('a[style="color: rgb(255, 102, 0)"]').remove('[style="color: rgb(255, 102, 0)"]');

    $('a[style="color: rgb(255, 102, 0)"]').remove();

    <a style="color: rgb(255, 102, 0)">not orange</a>

    <a style="color: rgb(255, 102, 0);">not orange</a>

【问题讨论】:

    标签: javascript jquery css styles


    【解决方案1】:

    你可以用这个:

    $('a[style="color: rgb(255, 102, 0)"]').css('color', '');
    

    但这只有在你的样式属性正好是"color: rgb(255, 102, 0)"时才有效。

    如果你想要更可靠的东西,例如接受其他样式属性或 CSS 规则中指定的颜色,你必须过滤:

    $('a').filter(function(){
       return $(this).css('color')=='rgb(255, 102, 0)'
    }).css('color', '');
    

    Demonstration

    【讨论】:

    • 谢谢!有没有办法从任何标签中过滤掉它,还是我必须指定每个我想要过滤的标签?
    • @JennC 是的,使用$('*') 而不是$('a')
    猜你喜欢
    • 1970-01-01
    • 2013-01-05
    • 2011-01-28
    • 1970-01-01
    • 1970-01-01
    • 2017-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多