呼叫事件我有以下代码重复一些时间,只有一些变化:与功能处理器+参数的jQuery
$('#mapContainer').on({
mouseenter: function() {
Map.ApplyEvents.Country(this.id);
},
click: function() {
Map.Zoom.State(this.id);
}
},
'.mapaCountry path');
// this is in another function
$('#mapContainer').on({
mouseenter: function() {
Map.ApplyEvents.State(this.id);
},
click: function() {
Map.Zoom.County(this.id);
}
},
'.mapaState path');
在所有的事件,我得叫一个匿名函数只是调用1功能在里面。
有没有办法挤进这个代码所需功能分配处理程序,还通知参数与this.id
?
我要实现的是这样的:
(注:我知道这是错误的语法。)
$('#mapContainer').on({
mouseenter: Map.ApplyEvents.Country(this.id),
click: Map.Zoom.State(this.id)
},
'.mapaCountry path');
$('#mapContainer').on({
mouseenter: Map.ApplyEvents.State(this.id);
click: Map.Zoom.County(this.id)
},
'.mapaState path');