亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

JavaScript - 測試 jQuery

引用 jQuery

如需測試 JavaScript 函式庫,您需要在網(wǎng)頁中引用它。

為了引用某個函式庫,請使用<script> 標籤,其src 屬性設定為庫的網(wǎng)址:

<!DOCTYPE html>
<html>
<head>
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js">//此處引用
</script>
</head>
<body>
</body>
</html>







#jQuery 描述

主要的jQuery 函數(shù)是$() 函數(shù)(jQuery 函數(shù))。如果您向該函數(shù)傳遞 DOM 對象,它會傳回 jQuery 對象,並帶有向其新增的 jQuery 功能。

jQuery 允許您透過 CSS 選擇器來選取元素。

在JavaScript 中,您可以指派一個函數(shù)來處理視窗載入事件:

使用JavaScript?

function myFunction(){????var obj=document.getElementById("h01");
????obj.innerHTML="Hello jQuery";

}

onload=myFunction;

使用jQuery?





########################################' ####function myFunction()###{###????$("#h01").html("Hello jQuery");###}####$(document).ready(myFunction);## ##########上面程式碼的最後一行,HTML DOM 文件物件被傳遞到jQuery :$(document)。 ############當您向 jQuery 傳遞 DOM 物件時,jQuery 會傳回以 HTML DOM 物件包裝的 jQuery 物件。 ######jQuery 函數(shù)會傳回新的 jQuery 對象,其中的 ready() 是一個方法。 ######由於在 JavaScript 中函數(shù)就是變數(shù),因此可以把 myFunction 作為變數(shù)傳遞給 jQuery 的 ready 方法。 #########注意:##################jQuery 傳回 jQuery 對象,與已傳遞的 DOM 物件不同。 ###jQuery 物件擁有的屬性和方法,與 DOM 物件的不同。 ######您無法在 jQuery 物件上使用 HTML DOM 的屬性和方法。 ? ?####################################實例比較:#########
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
<script src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>
<script>
function myFunction(){
$("#h01").html("Hello jQuery")
}
$(document).ready(myFunction);
</script>
</head>
<body>
<h1 id="h01"></h1>
</body>
</html>

對比

#
<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
<script src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>
<script>
function myFunction(){
$("#h01").attr("style","color:red").html("Hello jQuery")
}
$(document).ready(myFunction);
</script>
</head>
<body>
<h1 id="h01"></h1>
</body>
</html>

如您在上面的例子中看到的,jQuery 允許連結(jié)(鍊式文法).

連結(jié)(Chaining)是一種在同一物件上執(zhí)行多個任務的便捷方法。


繼續(xù)學習
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ alert($("#runoob").attr("href")); }); }); </script> </head> <body> <p><a href="http://ipnx.cn" id="runoob">php.cn</a></p> <button>顯示 href 屬性的值</button> </body> </html>