如何应用!重要的使用.css()?我在运用一种风格上有困难!important..我试过:$("#elem").css("width", "100px !important");这确实是没什么不应用任何宽度样式。是否有一种jquery-ish的方法可以在不需要覆盖的情况下应用这样的样式?cssText(这意味着我需要先解析它,等等)?编辑:我应该补充一下,我有一个带有!important样式,我试图用!important样式内联,所以使用.width()而且这种方法不起作用,因为它被我的外部程序覆盖了。!important风格。另外,将覆盖前一个值的值。计算,所以我不能简单地创建另一个外部样式。
4 回答

慕工程0101907
TA贡献1887条经验 获得超5个赞
!important
addClass()
:
.importantRule { width: 100px !important; }$('#elem').addClass('importantRule');
attr()
:
$('#elem').attr('style', 'width: 100px !important');
attr()
style
$('#elem').attr('style', function(i,s) { return s + 'width: 100px !important;' })

叮当猫咪
TA贡献1776条经验 获得超12个赞
var elem = $("#elem");elem[0].style.removeAttribute('width');elem[0].style.setProperty('width', '100px', 'important');
添加回答
举报
0/150
提交
取消