jQuery: The Write Less, Do More, JavaScript Library

jQuery 是一套物件導向式簡潔輕量級的 JavaScript Library。透過 jQuery 你可以用最精簡少量的程式碼來輕鬆達到跨瀏覽器 DOM 操作、事件處理、設計頁面元素動態效果、AJAX 互動等。

jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.

摘自 http://jquery.com/

jQuery 的程式碼長怎樣?

$('p.neat').addClass('ohmy').show('slow');

再談談 jQuery 的好

  1. 官方文件詳細 (重要)
  2. 簡潔不笨重,壓縮後大約 32kB (v1.12.4)
  3. 只要你有 JavaScript 的基礎,不用再多去學習一大堆新語法
  4. 不用去煩惱跨瀏覽器 (cross-browser) 的問題,jQuery 已經幫你作好了 (IE, Firefox, Safari, Opera, Chrome)
  5. 支援 CSS3 選擇器
  6. 社群活躍,你可以有很多人家寫好免費的 plugin 用
  7. 跟其它 library 一起使用也不衝突 (jQuery.noConflict())

學習 jQuery 之前你最好先了解

在輕鬆的使用 jQuery 之前,你必需先了解基本的 JavaScript、CSS 與 HTML。

如何使用 jQuery

先下載 jQuery Library http://jquery.com/download/

接著將此 JS 檔放進你網頁 HTML 的 <head></head> 之間

<script src="你的 jQuery 檔案路徑"></script>

或者透過 Google CDN 載入 jQuery (好處:免費、快)

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>