2012-07-23 258 views
2

我想模擬鼠標使用jQuery的事件處理,但事件處理程序不在測試環境中調用。可能是什麼原因?JQuery:鼠標事件觸發

+0

發佈您的代碼,以http://jsfiddle.net/。 我想解決你的問題:) – Yoeri 2012-07-23 09:20:45

回答

1

是這樣的嗎?

$(document).ready(function() { 
    $('#test, .comments').on('mouseenter', function() { 
     $('.comments').stop(true,true).show('slow'); 
    }); 
    $('#test').on('mouseleave', function() { 
     $('.comments').stop(true,true).hide('slow'); 
    }); 
})​;​ 

FIDDLE

也可以,只是縮短:

$('#test').on('mouseenter mouseleave', function(e) { 
    $('.comments').stop(true,true)[e.type==='mouseenter'?'show':'hide']('slow'); 
}); 

FIDDLE

+0

使用'.on()'而不是'bind'。 :) – 2012-07-23 09:29:44