DIV CSS 佈局教程網

this 與 $(this) 的差異:原生屬性與 jQuery 包裝
編輯:JQuery特效代碼     

兩者差異

this 代表原生 DOM 元素,$(this) 代表 jQuery 包裝後的物件。若使用原生屬性或方法,可用 this;若使用 jQuery 方法,則使用 $(this)。

範例概念

  • 取得連結文字:this 的 innerHTML 與 $(this) 的 html 可得到相同結果。
  • 取得 href:原生 getAttribute 或 jQuery attr 皆可。
  • 若 jQuery 未包裝原生方法,例如 form reset,可直接用 this 或 $(this) 的索引取值。
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved