【问题标题】:Adding '!important' property to css inside iframe using jquery使用jquery将'!important'属性添加到iframe中的css
【发布时间】:2015-11-03 15:42:29
【问题描述】:

我有一个框架并动态地将“标题”类应用于框架。 它工作正常,但需要在每个 css 属性的末尾添加“!important”。

我通过以下方式申请但没有工作。

var divblock = '.header';
$('#frame').contents().find('header').addClass('header');

$('#frame').contents().find(divblock).css({
    'color': objProp.css[pageSection]['color']+ '!important',
    'background-color': objProp.css[pageSection]['background']+'!important',
    'font-size': objProp.css[pageSection]['font-size']+'!important'
}); 

【问题讨论】:

  • 添加 !important 是不可能的 jQuery .css,你必须像 setAttribute("style", "width: 12px !important"); Plain JS 一样使用它
  • @abhi 不。它可以用jquery来完成。 .css(property,value,priority)
  • @RajaprabhuAravindasamy 这对我没用,所以我只使用了setAttribute 方法。
  • THIS 回答可能会有所帮助
  • @RajaprabhuAravindasamy 在 css 函数中这些参数没有重载:api.jquery.com/css

标签: jquery


【解决方案1】:

我们不能使用 jQuery 添加 !important 但你可以像下面这样覆盖样式。

// CSS styles 
.header{
  color:red;
 }

.importantHeader{
   color: black !important;
}

//script

$('#frame').contents().find('header').addClass('imporatantHeader');

不是这样,但你可以使用相同的类次数,为此你只需要编写一行代码 jQuery 代码

这叫做可重用。

祝你好运['}

【讨论】:

    猜你喜欢
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-26
    • 2013-04-25
    • 2016-09-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多