初步認識JavaScript函數庫jQuery,函數庫jquery

來源:互聯網
上載者:User

初步認識JavaScript函數庫jQuery,函數庫jquery

jQuery 庫可以通過一行簡單的標記被添加到網頁中。
jQuery 庫 - 特性

jQuery 是一個 JavaScript 函數庫。

jQuery 庫包含以下特性:

  •     HTML 元素選取
  •     HTML 元素操作
  •     CSS 操作
  •     HTML 事件函數
  •     JavaScript 特效和動畫
  •     HTML DOM 遍曆和修改
  •     AJAX
  •     Utilities

向您的頁面添加 jQuery 庫

jQuery 庫位於一個 JavaScript 檔案中,其中包含了所有的 jQuery 函數。

可以通過下面的標記把 jQuery 添加到網頁中:

<head><script type="text/javascript" src="jquery.js"></script></head>

請注意,<script> 標籤應該位於頁面的 <head> 部分。
基礎 jQuery 執行個體

下面的例子示範了 jQuery 的 hide() 函數,隱藏了 HTML 文檔中所有的 <p> 元素。
執行個體

<html><head><script type="text/javascript" src="jquery.js"></script><script type="text/javascript">$(document).ready(function(){$("button").click(function(){$("p").hide();});});</script></head><body><h2>This is a heading</h2><p>This is a paragraph.</p><p>This is another paragraph.</p><button type="button">Click me</button></body></html>

親自試一試
下載 jQuery

共有兩個版本的 jQuery 可供下載:一份是精簡過的,另一份是未壓縮的(供調試或閱讀)。

這兩個版本都可從 jQuery.com 下載。
庫的替代

Google 和 Microsoft 對 jQuery 的支援都很好。

如果您不願意在自己的電腦上存放 jQuery 庫,那麼可以從 Google 或 Microsoft 載入 CDN jQuery 核心檔案。
使用 Google 的 CDN

<head><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script></head>

使用 Microsoft 的 CDN

<head><script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script></head>


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.