jQuery 庫能夠經過一行簡單的標記被添加到網頁中。javascript
jQuery 是一個 JavaScript 函數庫。html
jQuery 庫包含如下特性:java
jQuery 庫位於一個 JavaScript 文件中,其中包含了全部的 jQuery 函數。jquery
能夠經過下面的標記把 jQuery 添加到網頁中:ajax
<head> <script type="text/javascript" src="jquery.js"></script> </head>
請注意,<script> 標籤應該位於頁面的 <head> 部分。api
下面的例子演示了 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.com 下載。動畫
Google 和 Microsoft 對 jQuery 的支持都很好。google
若是您不肯意在本身的計算機上存放 jQuery 庫,那麼能夠從 Google 或 Microsoft 加載 CDN jQuery 核心文件。
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs
/jquery/1.4.0/jquery.min.js"></script>
</head>
<head>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery
/jquery-1.4.min.js"></script>
</head>