replacement for hover() in jquery1.9?

删除回忆录丶 提交于 2019-12-14 03:34:34

问题


How do I use mouseneter mouseleave instead of hover(). Should i use them both instead of hover()?

$('#somegrid').hover(
function () {
    //something;
},

What about legacy code - I mean what goes in mouseenter , what goes in mouseleave? i just had one action on hover()


回答1:


Like this -

$('#somegrid').on('mouseenter',function(){
 // mouseenter
}).on('mouseleave',function(){
 //  mouseleave
});



回答2:


look at the api for hover

the hover function is shorhand for:

$( selector ).mouseenter( handlerIn ).mouseleave( handlerOut );

or if you are only passing in one handler:

$( selector ).on( "mouseenter mouseleave", handlerInOut );

the examples in the api illustrate this well.



来源:https://stackoverflow.com/questions/22349791/replacement-for-hover-in-jquery1-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!