Combining two event handling into a single event handling

This question already has an answer here:

  • jQuery multiple events to trigger the same function 10 answers

  • Or you can define the function:

    function mySuperDuperEventHandler()
    {
        $(!agent) {
    
            var milk   = $().height(),
                choco  = $().width();
    
            doThis();
    
        } else {
            var orange  = $().length(),
                apple   = $().width();
    
            orThis();
        }
    }
    

    And then assign it as the event handler:

    $(window).on('load resize',mySuperDuperEventHandler);
    

    您可以将多个事件与on()侦听器结合使用。

    $(window).on('load resize',function() {
    
            $(!agent) {
    
                var milk   = $().height(),
                    choco  = $().width();
    
                doThis();
    
            } else {
                var orange  = $().length(),
                    apple   = $().width();
    
                orThis();
            }
    
    });
    
    链接地址: http://www.djcxy.com/p/96910.html

    上一篇: 如何找到两个事件

    下一篇: 将两个事件处理组合成单个事件处理