2010-07-12 33 views
0

我正在做一些關於JQuery的自學,並且遇到了一個問題:
我試圖使用JQuery next()API來獲取數據從隱藏類型的文本框字段,但我沒有這樣做。
這裏是我的代碼:使用JQUery Next()API從隱藏的文本框中獲取數據

$(document).ready(function(){ 
    $(".Testing").click(function(){ 
    var what = $(this).next().val(); 
    alert(what); 
    }); 
}); 

<span class="Testing">Hello</span><br/> 
<input type="hidden" value="World"> 

<span class="Testing">Hi</span><br/> 
<input type="hidden" value="There"> 

你能幫我解決這個問題嗎?

參考鏈接: Grab the ID of a SPAN tag and add some value to a Text Box Field according to which tag has been clicked

回答

2

您可能忘記關閉對$(document).ready的調用。 它需要額外的});

<html> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
    $(".Testing").click(function(){ 
     var what = $(this).next().val(); 
     alert(what); 
    }); 
}); 
</script> 
</head> 
<body> 

<span class="Testing">Hello</span> 
<input type="hidden" value="World"> 

<span class="Testing">Hi</span> 
<input type="hidden" value="There"> 

</body> 
</html> 
0

的.next()是用於包含一組DOM對象的對象的jquery。

你會用它來做類似列表的事情。檢查出文檔: http://api.jquery.com/next/

其實你應該可以做你的嘗試。忽略這個。