jquery css 添加 !important 样式无效

一、问题

要用jquery中css方法覆盖css样式中的color: #998!important的样式。
原来用的是:
    $('#box').css({"width":"82px", "top":"8px", "color":"#fff!important"});
结果毫无疑问,没有效果。

二、结果

后,发现在用css方法添加 !important 时,需要用特殊的写法。即,
    $("#box").css("cssText","color:#fff!important;");
这种方法没有错。但在我修改的项目中,添加了好几个内联样式,写法错了,应写成:
    $("#box").css("cssText","width:82px;top:8px;color:white!important");
这种方式,!important 才有效果。
至于自己猜测的错误写法,还是不贴了。。

猜你喜欢

转载自blog.csdn.net/yan263364/article/details/82184773