我有一些
元素,它们每个都有CSS应用的
hover
效果。但我并不总是想要这个hover
效果; 它只应在特定条件下激活。
现在,当我的条件得到满足时,如何使用jQuery禁用那些hover
效果? 禁用hover
的代码是什么? 我无法访问CSS文件。
只需使用jQuery hover
,而不是CSS中的hover。
例如,使用以下代码替换CSS:
#Div1:hover { background-color: yellow; }
这是需要翻译的内容:Have this jQuery:
$("#Div1").hover(function() {
$(this).css("background-color", "yellow");
}, function() {
$(this).css("background-color", "");
});
同样的效果,你可以控制JS代码并添加条件。
实时测试案例:http://jsfiddle.net/THXuc/
<script>
$("someDiv").hover(function(event) {
//apply some conditions if yes
event.preventDefault();
else
return true;
});
</script>
.hover()
方法,为相关的
.css()
会将任何写入的内容附加到你的CSS中。 - ianace