好吧,一直在努力切换到 jQuery 1.7 的新功能和改进.on()
功能,而不是依赖 .live()。
这就是我的意思,当您有多个绑定时, .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 -如果你想在谷歌上了解更多,这一定是最糟糕的功能之一。