将两个事件处理组合成单个事件处理
这个问题在这里已经有了答案:
或者你可以定义该功能:
function mySuperDuperEventHandler()
{
    $(!agent) {
        var milk   = $().height(),
            choco  = $().width();
        doThis();
    } else {
        var orange  = $().length(),
            apple   = $().width();
        orThis();
    }
}
然后将其分配为事件处理程序:
$(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();
        }
});
上一篇: Combining two event handling into a single event handling
下一篇: JQuery function on window events: combine load and resize
