jQuery 實現方法的鏈式操作非常容易,善用這個特性可以讓程式碼更簡潔。
// 糟糕的寫法
$second.html(value);
$second.on('click',function(){
alert('hello everybody');
});
$second.fadeIn('slow');
$second.animate({height:'120px'},500);
// 建議的寫法
$second.html(value);
$second.on('click',function(){
alert('hello everybody');
}).fadeIn('slow').animate({height:'120px'},500);
更多高效 jQuery 實踐經驗。