jQuery 1.8.2 を使用して、イベント委任を使用して複数のイベントを単一のクラスにバインドします。
$(document).on("focus blur", ".myClass", function() {
console.log("Ba da boom.");
});
jQuery 1.8.2 を使用して、イベント委任を使用して複数のイベントを単一のクラスにバインドします。
$(document).on("focus blur", ".myClass", function() {
console.log("Ba da boom.");
});
複数のオンを連鎖させるか、マップを使用して複数のイベントを添付することができます。
複数の on を連鎖:
例:
$(document).on("focus", ".myClass", function(){
//do something
}).on("blur", ".myClass", function(){
//do something else
});
デモ: http://jsfiddle.net/MG8S7/4/
Map を使用してイベントを添付:
例:
$(".myClass").on({
focus: function(){
//do something
},
blur: function(){
//do something else
},
mouseenter: function(){
//do one more thing
}
});
デモ: http://jsfiddle.net/MG8S7/9/
お役に立てれば!