我是新來jquery和在學習階段。 我已經寫了一個測試程序。問題與「按鈕」和「:按鈕」選擇器
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("Button").click(function(){
$(this).parents(".ex").hide();
});
$(":button").click(function(){
$(this).parents(".ex").hide("slow");
});
});
</script>
<style type="text/css">
.ex{
background-color: #e5eecc;
padding: 7px;
border: solid 1px #c3c3c3;
}
</style>
</head>
<body>
<h3>Island Trading</h3>
<div class="ex">
<input type="button" name="hid" value="Hide Me slowly">
<p> Contact: Helen Bennett</p>
<p>Garden House Crowther Way</p>
<p>London</p>
</div>
<h3>Paris spécialités</h3>
<div class="ex">
<button type="button">Hide Me Quick</button>
<p> Contact: Marie Bertrand</p>
<p>265, Boulevard Charonne</p>
<p>Paris</p>
</div>
</body>
</html>
這是按預期工作。每當我點擊慢慢隱藏我,它隱藏得很慢。因爲帶有選擇器「:按鈕」的事件要求這樣做。和 類似的隱藏我快速 - 選擇器是「按鈕」,它很快隱藏起來。
但是,一旦我改變腳本中事件處理函數的順序,它們都被隱藏得很慢。 變化代碼
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(":button").click(function(){
$(this).parents(".ex").hide("slow");
});
$("Button").click(function(){
$(this).parents(".ex").hide();
});
});
</script>
我的問題是,我沒有改變只是爲了被修改的選擇。對於選擇器「按鈕」,我已經寫了事件處理函數,只隱藏並沒有指定「慢」。但是,它隱藏得很慢。你可以請看看它,讓我知道爲什麼?
非常感謝!這是一個簡單的例子,很好的解釋。 – satya 2010-07-06 13:45:07