一般來說,最好盡可能合併函式呼叫,以減少重複與提升效能。
// 糟糕的寫法
$first.click(function(){
$first.css('border','1px solid red');
$first.css('color','blue');
});
// 建議的寫法
$first.on('click',function(){
$first.css({
'border':'1px solid red',
'color':'blue'
});
});
更多高效 jQuery 實踐經驗。