我剛開始jQuery教程,我對jQuery動畫的加載順序有個基本問題。加載jQuery動畫的順序
單擊鏈接導致兩個警報和隱藏的動畫出現,當我使用下面的HTML代碼:,
<body>
<a href="http://jquery.com/">jQuery</a>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("a").click(function(event){
alert("As you can see, the link no longer took you to jquery.com");
event.preventDefault();
});
$("a").click(function(event){
event.preventDefault();
$(this).hide("slow");
});
});
</script>
</body>
然而,當我在第二個點擊功能出的document.ready功能,所以代碼如下所示,彈出窗口出現,文本消失,但隱藏動畫不會發生。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery demo</title>
<style>
a.test { font-weight: bold; }
</style>
</head>
<body>
<a href="http://jquery.com/">jQuery</a>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("a").click(function(event){
alert("As you can see, the link no longer took you to jquery.com");
event.preventDefault();
});
});
$("a").click(function(event){
event.preventDefault();
$(this).hide("slow");
});
</script>
</body>
</html>
任何人都可以解釋爲什麼隱藏動畫只顯示第一個例子,而不是第二個?
謝謝,我會研究什麼是DOM和處理綁定如何工作。 –