有人可以告诉我使用 bind() 分配事件处理程序有什么区别:
$(function () {
$('someElement')
.bind('mouseover', function (e) {
$(this).css({
//change color
});
})
.bind('mouseout', function (e) {
$(this).css({
//return to previous state
});
})
.bind('click', function (e) {
$(this).css({
//do smth.
});
})
});
使用 each() 完成相同的任务:
$('someElement').each(function () {
$(this).mouseover(function () {
$(this).css({/*change color*/ })
.mouseout(function () {
$(this).css({/*return to previous state*/ });
});
});
});