2011-09-14 52 views

回答

7

你應該能夠做到這一點:

$('#myTableRow').find('input, select, textarea').each(function() 
{ 
}); 
+0

感謝您的答覆。它不會在tr中返回任何其他元素,如span和div嗎? – ashishjmeshram

+0

對不起,以上將選擇任何元素。一秒鐘,我會解決它。 – Tejs

+0

固定爲選擇表單元素。 – Tejs

0

我建議:

$('table input, table textarea, table select').each(function() { ... }); 
0

對於表你可以選擇行ECT所有輸入這樣的:

var myInputFields = $("#myTable tr input[type='text']"); 

這將只選擇輸入,無論有多少個層次進深一間錶行 - 這樣你就可以擁有已DIV> S,P>和其他的東西纏行輸入>秒。

您可以使用jQuery.each或簡單的i = 0-> myInputFields.length循環所有輸入字段。

myInputFields.each(function(i,v){ 
    var v = $(v); 
    console.debug(v.html(),v.val()); 
}); 

您可以像simoncereska的答案中的示例一樣簡單地擴展選擇器以獲取更多輸入/ textareas等。

0

如果你想在一個特定的行輸入:

HTML

<table> 
    <tr id="the_row"> 
    <td><input type="text" value="1"/></td> 
    <td><input type="text" value="2"/></td> 
    </tr> 
    <tr> 
    <td><input type="text" value="3"/></td> 
    <td><input type="text" value="4"/></td> 
    </tr> 
</table> 

的Javascript

$("#the_row :input").each(function() { 
    console.log(this.value); 
}); 

(注::input選擇匹配所有inputselecttextareabutton種元素)

DEMOhttp://jsfiddle.net/WuamV/