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

后端 未结 4 1959
误落风尘
误落风尘 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:46

    I just want to pass both event handlers in one object, like I do in the first example.

    In this case you could attach the two events together, then differentiate them in the handler itself, like this:

    $('#results tbody').on('mouseenter mouseleave', 'tr', function (e) {
        if (e.type == "mouseenter") {
            $(this).find('.popup').show();
        }
        else {
            $(this).find('.popup').hide();
        }
    });
    

提交回复
热议问题