[英]Jquery addClass and Remove Class on hover
好的,當鼠標懸停在元素#searchput
時,我想向元素#searchput
添加類cfse_a
,然后當鼠標懸停在元素上時,將類cfse_a
刪除。
將hover
事件與addClass
和removeClass
方法一起使用:
$("#searchput").hover(function() {
$(this).addClass("cfse_a");
}, function() {
$(this).removeClass("cfse_a");
});
演示: http : //jsfiddle.net/G23EA/
$('#searchput').hover(function() {
$(this).addClass('cfse_a'); // add class when mouseover happen
}, function() {
$(this).removeClass('cfse_a'); // remove class when mouseout happen
});
您還可以使用:
$('#searchput').hover(function() {
$(this).toggleClass('cfse_a');
});
$("#searchput").hover(function() {
$(this).addClass("cfse_a");
}, function() {
$(this).removeClass("cfse_a");
});
使用它。希望對您有所幫助!
希望這可以幫助。
$('#searchput').mouseover(function() {
$(this).addClass('cfse_a');
}).mouseout(function(){
$(this).removeClass('cfse_a');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.