jQuery - convert .live() to .on()

后端 未结 4 1961
误落风尘
误落风尘 2020-12-11 05:06

How do I go about combining this old jQuery code into the v1.7 .on()?

v1.3 .live():

    $(\'#results tbody tr\').live({
            


        
4条回答
  •  醉梦人生
    2020-12-11 05:42

    You can pass an event-map as the first parameter:

    $('#results tbody').on({
        'mouseenter' : function () {
            $(this).find('.popup').show();
         },
        'mouseleave' : function () {
            $(this).find('.popup').hide();
        }
    }, 'tr');
    

    jQuery documentation:

    .on( events-map [, selector] [, data] ),
    events-map A map in which the string keys represent one or more space-separated event types and optional namespaces, and the values represent a handler function to be called for the event(s).

提交回复
热议问题