【问题标题】:can i add css with !important , only using jquery我可以用 !important 添加 css 吗,只使用 jquery
【发布时间】:2012-08-02 07:56:51
【问题描述】:

你好,我正在使用 jquery

我想将带有important property 的css 颜色添加到标签

我目前正在尝试

 jQuery(this).css('color','green !important')

不使用类

喜欢

label_class
{
    background-color:#f2f2f2 !important;
}

并像使用一样

jQuery(this).addClass('label_class');

我可以只用jquery来做吗,请帮忙

【问题讨论】:

标签: javascript jquery css


【解决方案1】:

是的,这并不难,但你应该尽量避免一直使用 !important。

$("#tabs").css("cssText", "height: 650px !important;");

这是一个类似问题的链接How to include !important in jquery

希望这会有所帮助:)

【讨论】:

    【解决方案2】:

    您永远不需要这样做。 !important 标志表示样式应该优先。使用 jQuery,您将样式内联应用于元素,因此它已经具有最高优先级。

    请注意,如果您使用的是!important,您可能做错了什么。考虑重组您的 CSS 选择器以确保您不需要它。

    【讨论】:

      猜你喜欢
      • 2012-08-07
      • 1970-01-01
      • 1970-01-01
      • 2012-09-04
      • 2015-11-03
      • 2011-10-30
      • 2011-03-26
      • 2012-08-11
      • 2012-02-27
      相关资源
      最近更新 更多