jquery - javascript 阻止 css 代码

标签 jquery html css

<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/

相关文章:

html - 我可以用纯 css 创建交叉线背景框吗

html - 如何创建点击打开电子邮件编辑器的图片

CSS - 自定义标题设置

css - 带有表格边框的 Chrome css 问题

javascript - 使用 Javascript 选择菜单 onChange DIV 元素

javascript - 我可以将切换 CSS 应用于多个元素吗?

javascript - 在 html5 Canvas 内按下空格键时为玩家子弹设置动画

jquery - 如何使用 jQuery 过滤选择框选项?

javascript - jQuery,不适用于跨度

jQuery 未捕获类型错误 : Property '$' of object [object Window] is not a function