jQuery 庫可以通過一行簡單的標記被添加到網(wǎng)頁中。
jQuery 是一個 JavaScript 函數(shù)庫。
jQuery 庫包含以下特性:
jQuery 庫位于一個 JavaScript 文件中,其中包含了所有的 jQuery 函數(shù)。
可以通過下面的標記把 jQuery 添加到網(wǎng)頁中:
<head>
<script type="text/javascript" src="jquery.js"></script>
</head>
請注意,<script> 標簽應(yīng)該位于頁面的 <head> 部分。
下面的例子演示了 jQuery 的 hide() 函數(shù),隱藏了 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>
Google 和 Microsoft 對 jQuery 的支持都很好。
如果您不愿意在自己的計算機上存放 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>
如對本文有疑問,請?zhí)峤坏浇涣髡搲瑥V大熱心網(wǎng)友會為你解答!! 點擊進入論壇