2012-07-23 257 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