Jquery MouseOut事件触发不充分

Jquery MouseOut事件触发不充分,jquery,mouseevent,mouseout,Jquery,Mouseevent,Mouseout,我的页面上有如下HTML代码: <li><img width="100" alt="3Caballeros.png" onmouseover="show_buttons();"</img></li> } 使用prepend()方法添加图像,结果如下: 我不知道您的具体设置(没有CSS等),但以下更改可能会起到作用: function show_buttons(item){ var parent =$('img[alt="'+item.alt+'"]'

我的页面上有如下HTML代码:

<li><img width="100" alt="3Caballeros.png" onmouseover="show_buttons();"</img></li>
}

使用prepend()方法添加图像,结果如下:


  • 我不知道您的具体设置(没有CSS等),但以下更改可能会起到作用:

    function show_buttons(item){
    var parent =$('img[alt="'+item.alt+'"]').parent();
    alert(parent.prop('tagName'));    //says LI
    parent.find('img').fadeIn();      //shows the other images in the LI (they are added by JavaScript)
    item.onmouseover =function () {};   //removes the event listener to the image
    parent.mouseout( parent, function(){
        parent.find('img[alt!="'+item.alt+'"]').fadeOut();
    });
    parent.mouseover( parent, function(){
        parent.find('img[alt!="'+item.alt+'"]').fadeIn();
    });
    
    另请参见此

    问题的(可能)原因
    关于
    .mouseover()

    “由于事件冒泡,此事件类型可能会导致许多麻烦。例如,在本例中,当鼠标指针移动到内部元素上时,将向该元素发送一个鼠标悬停事件,然后向下流到外部。这可能在不适当的时候触发绑定的鼠标悬停处理程序。”


    在您的情况下,当从一个图像移动到下一个图像时,图像上会生成一个mouseout事件,然后冒泡到包含
    li
    ,导致出现意外行为。使用iseems是一个更好的选择!

    可以显示更多的代码。例如,这些代码到底是什么动态添加的图像…我刚刚编辑了这篇文章。当我用show()和hide()替换fadeIn()和fadeOut()时效果会很好…但我仍然希望我的问题得到回答。嗯…我刚刚看到了这条评论。正如我在回答中所说,除非我知道更多关于设置(元素布局、CSS属性等)的信息,否则我将在黑暗中拍摄:)
     <li><img class="first_button" src="images/first.png" style="display: none;">
     <img class="second_button" src="images/second.png" style="display: none;">
     <img width="100" alt="3Caballeros.png" onmouseover="show_buttons();"</img></li>
    
    // Replace 'parent.mouseout(...' with:
    parent.mouseleave(...
    
    // Replace 'parent.mouseover(...' with:
    parent.mouseenter(...