jQuery的簡單使用

在網頁中加入 jQuery

#可以透過多種方法在網頁中加入 jQuery。 您可以使用以下方法:

  • 從jquery.com 下載jQuery 庫

  • 從CDN 載入jQuery, 如從Google 載入jQuery


#下載jQuery

有兩個版本的jQuery 可供下載:

  • #Production version - 用於實際的網站中,已精簡和壓縮。

  • Development version - 用於測試和開發(未壓縮,是可讀的程式碼)

以上兩個版本都可以從jquery .com 中下載。

jQuery 函式庫是一個JavaScript 文件,您可以使用HTML 的<script> 標籤來引用它:

<head>
<script src="jquery-1.10.2 .min.js"></script>
</head>

#: 將下載的檔案放在網頁的相同目錄下,就可以使用jQuery。



##如果您不希望下載並存放jQuery,那麼也可以透過CDN(內容分發網路) 引用它。

百度、又拍雲端、新浪、Google和微軟的伺服器都存有 jQuery 。

如果你的網站使用者是國內的,建議使用百度、又拍雲、新浪等國內CDN地址,如果你網站使用者是國外的可以使用Google和微軟。

附註:本站實例皆採用百度 jQuery CDN函式庫。

<head>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
< ;/script>
</head>

實例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php.cn</title>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
 <script>
 $(document).ready(function(){
 $("#hide").click(function(){
 $("p").hide();
 });
 $("#show").click(function(){
 $("p").show();
 });
 });
 </script>
</head>
<body>
 <p>欢迎大家来到php.cn</p>
 <button id="hide">隐藏</button>
 <button id="show">显示</button>
</body>
</html>
繼續學習
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php.cn</title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("#hide").click(function(){ $("p").hide(); }); $("#show").click(function(){ $("p").show(); }); }); </script> </head> <body> <p>欢迎大家来到php.cn</p> <button id="hide">隐藏</button> <button id="show">显示</button> </body> </html>
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!