有没有办法结合这两种在jQuery中处理事件附件的方法?
$('selector').on({
mouseenter: function() {},
mouseleave: function() {},
mousedown: function() {},
mouseup: function() {}
});
我更喜欢以前的方法,但需要类似以下的方法来处理“实时”事件(问题是如果处理程序之间有注释,这将不起作用):
$(document).on('mouseenter', 'selector1', function(){})
.on('mouseleave', 'selector2', function(){})
.on('mousedown', 'selector3', function(){})
.on('mouseup', 'selector4', function(){});
但是,是否有解决方法可以做到这一点?:
$(document).on({
mouseenter: 'selector1': function() {},
mouseleave: 'selector2': function() {},
mousedown: 'selector3': function() {},
mouseup: 'selector4': function() {}
});
更新
我最终得到了这个简单的on
-wrapper 函数:https ://gist.github.com/4191657
用法很简单:
$(document).act(
['mouseenter', 'selector1', function() {}],
['mouseleave', 'selector2', function() {}],
['mousedown', 'selector3', function() {}],
['mouseup', 'selector4', function() {}]
);
对此有何建议或改进?