【发布时间】:2010-10-19 21:13:18
【问题描述】:
谁能告诉我使用 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*/ });
});
});
});
【问题讨论】:
-
您的第二个示例没有演示“每个”方法。只是让你知道......
标签: javascript jquery function bind each