<p class='sent' id='abc'>abc</p>
<p class='sent' id='abb'>abb</p>
<p class='sent' id='acc'>acc</p>
CSS
.sent:hover{
background-color:#e1e1e1; // works until the first click on .sent
}
js
$(".sent").click(function() {
$('.sent').css('background-color', 'transparent'); //works
$(this).css('background-color', '#e1e1e1'); //works
});
第一次点击sent
后,css sent:hover
不起作用!?
最佳答案
内联样式优先于样式 block 中定义的规则。
尝试删除 background-color
样式,而不是将其设置为 transparent
:
$(".sent").click(function() {
$(".sent").css("background-color", "");
$(this).css("background-color", "#e1e1e1");
});
关于jquery - javascript 阻止 css 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19376944/