2013-06-02 37 views
0

我試圖在具有多個文本區域的情況下獲取特定textarea的值。 確實,我得到了第一個的價值,但我無法得到下一個。 我已經嘗試了以下,但沒有工作。從一組文本中獲取一個textarea的值

// jquery: 
$('.SendDescription ').click(function() { 
var description = $('.description ').val(); 
//var description = $(this).closest('label').find('.description').val(); !!! Not working ... 
// var description = $(this).prev('.description').val(); !!! Not working ... 
if (description.length < 3) { 
    // do NOT process the form. 
    } 
// html: 
1- <textarea class="description ></textarea> 
<input type="button" value=" send " class="SendDescription " /> 

2- <textarea class="description ></textarea> 
<input type="button" value=" send " class="SendDescription " /> 

3- <textarea class="description ></textarea> 
<input type="button" value=" send " class="SendDescription " /> 
    .............. 

謝謝。

+0

您的標記中的類屬性加引號未關閉不必要的空間等等,不知道這是複製粘貼問題。 CHeck this http://jsfiddle.net/C92N6/ – PSL

+0

http://stackoverflow.com/users/1009603/psl它正在處理jsiddle b ut我得到錯誤信息: – test

+0

TypeError:描述未定義 if(description.length <3){ – test

回答

-1

如果按鈕和textarea的是兄弟姐妹,你可以這樣做:

var description = $(this).parent().find('.description').val(); 
+3

''''最接近('*'')與'parent()'相同。 – SLaks

+0

@SLaks - 是的!在這種情況下,使用父級()清理器。 – techfoobar

+0

一直在使用'closest()',並且一會兒忘了'parent()'的存在:-) – techfoobar

相關問題