我有这个密码
$('#downvotebutton').click(function() {
$(this).css('background-color', 'red !important');
console.log('foo');
//more当按下按钮时,'foo‘会返回到控制台,但是背景色不会改变。jQuery链接到页面的其他地方,并在其他地方工作。可能是什么原因?
发布于 2014-02-27 13:49:45
你真的需要!important吗?以下将起作用:
$(this).css('background-color', 'red');或者如果你需要!important
$(this).css("cssText", "background-color: red !important;");发布于 2014-02-27 13:46:32
不能使用!important语句使用jQuery css()方法。
你可以用:
$(this).attr('style', function(_, rules) {
var newval = rules?rules:"";return newval + ';background-color: red !important;'
});https://stackoverflow.com/questions/22070397
复制相似问题