jQuery 簡介

jQuery 簡介

jQuery 庫能夠經過一行簡單的標記被添加到網頁中。javascript

jQuery 庫 - 特性

jQuery 是一個 JavaScript 函數庫。html

jQuery 庫包含如下特性:java

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

向您的頁面添加 jQuery 庫

jQuery 庫位於一個 JavaScript 文件中,其中包含了全部的 jQuery 函數。jquery

能夠經過下面的標記把 jQuery 添加到網頁中:ajax

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

請注意,<script> 標籤應該位於頁面的 <head> 部分。api

基礎 jQuery 實例

下面的例子演示了 jQuery 的 hide() 函數,隱藏了 HTML 文檔中全部的 <p> 元素。ide

實例

<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 的支持都很好。google

若是您不肯意在本身的計算機上存放 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>

 

文章源於http://www.w3school.com.cn/

相關文章
相關標籤/搜索