gpt4 book ai didi

jquery - .on() mouseenter 事件有效,但单击不起作用 jquery 2

转载 作者:行者123 更新时间:2023-12-01 07:18:19 24 4
gpt4 key购买 nike

我的脑子一片困惑。谁能告诉我为什么这适用于“mouseenter”但不适用于“click”?

http://jsfiddle.net/jxUGw/3/

//////THIS DOESNT WORK
$('#view_panel').on('click', 'img.main_image', function(){
$(this).parent().find('div.image_box').show();
});

$('#view_panel').on('click', 'img.main_image', function(){
$(this).parent().find('div.image_box').hide();
});


/////THIS WORKS
$('#view_panel').on('mouseenter', 'img.main_image', function(){
$(this).parent().find('div.image_box').show();
});

$('#view_panel').on('mouseleave', 'img.main_image', function(){
$(this).parent().find('div.image_box').hide();
});

最佳答案

绑定(bind)的第二个事件在第一个事件之后立即触发。因此 div 一显示就被隐藏。

尝试使用toggle()代替。

关于jquery - .on() mouseenter 事件有效,但单击不起作用 jquery 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16799821/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com