动态添加CSS

时间:2018-07-30 10:38:35

标签: jquery css

我尝试了以下JQuery方法来动态替换CSS值,但是它不起作用。知道哪一部分不对吗?

在我的html中:

<div class="svg">
     <button class="type_1"></button>
</div>

我当前需要动态替换的CSS:

svg .type_1    
{
    stroke: rgb(255, 128, 0);
    fill: rgb(255, 128, 0);
}

我当前无法使用的方法:

 $('.svg .type_' + list.id).css({
        stroke: list.hex_color,
        fill: list.hex_color
 });

1 个答案:

答案 0 :(得分:0)

您遇到串联问题,必须将css用引号引起来

$('.svg .type_' + list.id).css({
        'stroke': list.hex_color,
        'fill': list.hex_color
 });