我有这个代码
$('#downvotebutton').click(function() {
$(this).css('background-color', 'red !important');
console.log('foo');
//more
当向下投票按钮被点击时,“foo”返回到控制台,但背景颜色没有改变。 jQuery 链接到页面的其他地方并在其他地方工作。可能是什么原因?
最佳答案
你真的需要 !important
吗?以下将起作用:
$(this).css('background-color', 'red');
或者如果你需要 !important
:
$(this).css("cssText", "background-color: red !important;");
关于javascript - $(this).css 不改变 css 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22070397/