DIV CSS 佈局教程網

高效 jQuery:請優先使用 on() 函式
編輯:JQuery常見問題     

在新版 jQuery 中,較簡短的 on("click") 用來取代類似 click() 這樣的函式。在之前的版本中,on() 等同於 bind()。自 jQuery 1.7 版本後,on() 成為附加事件處理程式的首選方法。然而,出於一致性考量,你可以簡單地全部改用 on() 方法。

點擊查看 jQuery 的 on 函式。

// 糟糕的寫法

$first.click(function(){
  $first.css('border','1px solid red');
  $first.css('color','blue');
});

$first.hover(function(){
  $first.css('border','1px solid red');
})

// 建議的寫法

$first.on('click',function(){
  $first.css('border','1px solid red');
  $first.css('color','blue');
})

$first.on('hover',function(){
  $first.css('border','1px solid red');
})

更多高效 jQuery 實踐經驗。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved