您好,我正在动态添加一些元素,现在我正在尝试使用 on()
绑定(bind)和 hover()
,但这似乎不适用于回调函数。有什么想法吗?
jQuery:
$(document.body).on('hover', 'div.settings-container', function () {
$(this).find('ul.settings-links').fadeIn();
}, function () {
$(this).find('ul.settings-links').fadeOut();
});
jsfiddle被简化了。
最佳答案
在jQuery中,$(selector).hover(handlerIn, handlerOut)
只是的快捷方式
$(selector).mouseenter(handlerIn).mouseleave(handlerOut);
hover
不是事件,您需要使用 mouseenter
和 mouseleave
代替。
$('body').on({
mouseenter: function() {
$(this).find('ul.settings-links').fadeIn();
},
mouseleave: function() {
$(this).find('ul.settings-links').fadeOut();
}
}, 'div.settings-container');
关于javascript - 带有 on() 和绑定(bind)的悬停回调函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12853622/