jQuery 是專精於簡化 DOM、AJAX、與 Event 操作的 JavaScript 函式庫。JavaScript 開發者們常常使用它。
jQuery 用 $(selector).action()
格式,指派元素到指定的事件。詳細來說, $(selector)
會呼叫 jQuery 選取 selector
元素,並指派它到稱作 .action()
事件的 API。
$(document).ready(function(){
alert("Hello World!");
$("#blackBox").hide();
});
上面這段 jQuery 程式碼,會執行與這段原生 JavaScript 程式碼相同的事情:
window.onload = function() {
alert( "Hello World!" );
document.getElementById("blackBox").style.display = "none";
};
下載 jQuery
npm | bower (solo file) | Google CDN |
---|---|---|
npm install jquery |
bower install https://code.jquery.com/jquery-3.4.1.min.js |
https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js |
深入理解
基本知識
- 維基百科的 jQuery
- jQuery 官方網站