2013-04-22 28 views
0

一個簡單的形式在這樣一個parrent DIV:jQuery的獲取每個表單輸入,進行了使用正確的類

<form method="post"> 
<div class="success"> 
<input type="text" name="username" id="username"/> 
</div> 
<div class="notsuccess"> 
<input type="password" name="password" id="password"/> 
</div> 
<input type="submit" name="submit" id="submit" value="submit" /> 
</form> 

是否有可能使用jQuery獲得具有parrent DIV列表或每個輸入數組有一班成功? 我想做一些驗證。

+0

你還嘗試過什麼嗎? – j08691 2013-04-22 19:25:59

回答

2

我讀它從字面上

(1)每個輸入的列表或陣列

(2),其具有*父DIV與類成功的

然後$('div.success input')

0

你可以嘗試

$("input").parent("div.success").each(function() { 
    //code here 
}); 
0

你可以試試這個:

var $elements = $('input').parent('.success');

遍歷所有這些,你可以使用:

$('input').parent('.success').each(function(i, ele) { 
    $(this); // This is each .success element. 
}); 
0
$('input', $('div.success')) 

迄今爲止最簡單的答案。請記住,默認情況下,$()選擇器將創建一個jQuery對象,其中所有DOM節點都與該選擇相匹配。這意味着你不必創建一個數組,它已經完成了。

相關問題