使用jQuery,这是更好,性能代价:jQuery性能:使用每个按钮的选择器或使用一个选择器和检查类?
添加事件处理程序为每个按钮:
$(".toolbar .add").click() {
// Add stuff here
}
$(".toolbar .remove").click() {
// Remove stuff here
}
$(".toolbar .clear").click() {
// Clear stuff here
}
或添加一个事件处理程序,并检查类(或其他相关属性),看看哪些采取的行动:
$(".toolbar .button").click() {
if($(this).hasClass("add"))
// Add stuff here
} else if($(this).hasClass("remove")) {
// Remove stuff here
} else if($(this).hasClass("clear")) {
// Clear stuff here
}
}
或者还有更好的办法吗?
(如果这有什么差别,我实际使用delegate
,不bind
在我的应用程序)
在我的情况下,我不得不使用'委托',因为工具栏加载了Ajax。 – Chaim