如果我的标记看起来像这样:性能开销
<button id="button-1" class="nice">
<button id="button-2" class="nice">
<button id="button-3" class="nice">
,我定义以下的jQuery:
$(".nice").click(function() {
// something happens
});
多少事件监听器成立? 1或3?
如果我有1000个按钮而不是3个,应该使用事件委托吗?
如果这些类在标记中包含大量元素,那么在元素类中不定义jQuery调用是否最好,性能明智?
你用什么工具进行基准测试? – fingerprint 2009-07-20 14:55:22
如果您使用Firefox,请尝试使用firebug(http://getfirebug.com)。 – SolutionYogi 2009-07-20 17:09:54
我通常只写我自己的,不太难。 – 2009-07-20 21:33:08