好吧一直在努力切換到jQuery 1.7的新功能和改進的.on()
函數,而不是依賴.live()。在單個.on()調用中綁定多個事件
下面是當我有多個綁定時,得到我的.live()非常棒,讓你在一個簡單的函數中完成它們。例如:
$('.my_thing').live({
mouseover: function(e) {
console.log('hey imma moused over');
},
mouseout: function(e) {
console.log('hey imma moused out');
}
});
很簡單!你如何使用.on()來做到這一點?這裏距離我所能得到的距離還很近,並且仍然感覺混亂。
$(document).on('mouseover','.my_thing', function(e) {
console.log('hey imma moused over');
}).on('mouseout','.my_thing', function(e) {
console.log('hey imma moused out');
});
感覺凌亂,不是嗎?一定會有更好的辦法。
PS - 這一定是最壞的功能一個EVER如果你想了解更多關於它的谷歌。
具有諷刺意味的是,你要鏈接到的答案可以在上面找到的文檔類:P – Esailija 2012-04-11 00:00:35
那是什麼.on(events-map [,selector] [,data])在說什麼?我有時只是無視例子地看着這些東西。 – Mojowen 2012-04-21 00:28:55