我是JQuery的新手。我有一个带有css类的按钮,它工作得很好,但我想在悬停按钮时更改css类。
我该如何对此进行编码?
这就是我到目前为止得到的:
//on top in my heading:
<script type="text/javascript">
$('btn').hover(function () {
alert("Test"); //just for testing
});
</script>
//my button:
<button id="btn" class="default_btn">ButtonText</button> 发布于 2011-08-10 17:12:10
如果您想在jQuery中选择id,您只需像在css:#id中那样,在本例中为#btn
jQuery帮助器函数hover通常需要回调。一个位于鼠标上方,另一个位于鼠标输出。
$(document).ready(function(){
$('#btn').hover(function(){
alert("over");
},function(){
alert("out");
});
});另一种方法是检测事件类型:
$(document).ready(function(){
$('#btn').hover(function(event){
if (event.type == "mouseenter") {
console.log("over");
} else {
console.log("out");
}
});
});函数悬停将函数绑定到jQuery对象。mouseenter和mouseleave。因此,我们可以假设如果它不是mouseenter,那么它就是mouseleave。
https://stackoverflow.com/questions/7008181
复制相似问题