假设您可以选择将函数应用于单个 DOM 元素或它们的列表:
个人:
$('#element1').click(function () {
$(this).hide();
return false;
});
$('#element2').click(function () {
$(this).hide();
return false;
});
$('#element3').click(function () {
$(this).hide();
return false;
});
与集合:
$('#element1, #element2, #element3').click(function () {
$(this).hide();
return false;
});
除了编写更少的代码之外,将函数应用于集合是否有任何计算优势?代码会运行得更快吗?
我问的原因是因为我的元素是 JS 对象,我需要单独处理它们。