<分区>
<分区>
我正在尝试使用以下语句应用内联 CSS。
$('.WarningCount').parent().css('margin-left', '-1.4% !important;');
但它不起作用,它不只是被应用。我在开发人员控制台中看不到这种样式。我必须覆盖整个样式才能使其正常工作。
$('.WarningCount').parent().attr('style', 'margin-left:-1.4% !important;');
任何可能是这里真正问题的原因。
最佳答案
Note: .css() ignores !important declarations. So, the statement $( "p" ).css( "color", "red !important" ) does not turn the color of all paragraphs in the page to red. It's strongly advised to use classes instead; otherwise use a jQuery plugin.
虽然,你可以引用this answer并使用 cssText 属性
const target = $('.WarningCount').parent();
target.css('cssText', target.attr('style')+'margin-left: -1.4% !important;');
关于jQuery .css 不适用于父容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52002012/