试图弄清楚如何将 Jquery .on() 方法与具有多个关联事件的特定选择器一起使用。我以前使用 .live() 方法,但不太确定如何使用 .on() 来完成相同的壮举。请在下面查看我的代码:
$("table.planning_grid td").live({
mouseenter:function(){
$(this).parent("tr").find("a.delete").show();
},
mouseleave:function(){
$(this).parent("tr").find("a.delete").hide();
},
click:function(){
//do something else.
}
});
我知道我可以通过调用来分配多个事件:
$("table.planning_grid td").on({
mouseenter:function(){ //see above
},
mouseleave:function(){ //see above
}
click:function(){ //etc
}
});
但我相信 .on() 的正确使用是这样的:
$("table.planning_grid").on('mouseenter','td',function(){});
有没有办法做到这一点?或者这里的最佳做法是什么?我尝试了下面的代码,但没有骰子。
$("table.planning_grid").on('td',{
mouseenter: function(){ /* event1 */ },
mouseleave: function(){ /* event2 */ },
click: function(){ /* event3 */ }
});
提前致谢!