As shown below, the class tag 'nav_hover' has been removed. It is expected that the binding event handler 'hover' should be detached to the DOM.
However the trigger is still there even the aim li has no class named 'nav_hover'.
[img]http://dl2.iteye.com/upload/attachment/0095/4928/8a930a10-bac3-3d97-b102-f2e5af6306e1.jpg[/img]
To solve the problem , we must use the binding method for furture elements.
$(document).on(event,selector,function);
In this senario, the code that works is :
I have no idea how to combine 'hover' and 'on' together.
Well that does not matter as it works already.
However the trigger is still there even the aim li has no class named 'nav_hover'.
[img]http://dl2.iteye.com/upload/attachment/0095/4928/8a930a10-bac3-3d97-b102-f2e5af6306e1.jpg[/img]
To solve the problem , we must use the binding method for furture elements.
$(document).on(event,selector,function);
In this senario, the code that works is :
$(document).on("mouseenter",".nav_hover",function(){
$(this).css("background-color", "#ee8296");
});
$(document).on("mouseleave",".nav_hover",function(){
$(this).css("background-color", "#fff");
});I have no idea how to combine 'hover' and 'on' together.
Well that does not matter as it works already.
本文探讨了在JavaScript中如何正确处理DOM元素的鼠标悬停事件绑定,通过使用$(document).on()方法避免事件绑定冲突,解决了在特定元素上应用悬停样式效果的问题。

536

被折叠的 条评论
为什么被折叠?



