Infinity178,
$(function() {
var ev = {
click: function() {
console.log("click")
},
focusin: function() {
console.log("focusin")
}
};
$("span").each(function(indx, el) {
el = $(el);
var data = el.data();
Object.keys(data).forEach(function(key) {
ev[key] && el.on(key, ev[key])
})
})
});
или так
$(function() {
var ev = {
click: function() {
console.log("click")
},
focusin: function() {
console.log("focusin")
}
};
Object.keys(ev).forEach(function(key) {
$("[data-" + key + "]").on(key, ev[key])
})
});