我有這個樣本http://jsfiddle.net/7aDak/927/。我需要遍歷每個表格的每一行的下拉列表和textarea,並基於此創建一個字符串。我不能使用ID的。我會怎麼做?提前致謝 。循環遍歷多個表的子元素
0
A
回答
1
您的代碼幾乎設立..只需要輕微的修正..見下文,
DEMO:http://jsfiddle.net/7aDak/931/
$("#btnSave").click(function() {
$(".templateTable").each(function() {
//v-- Used $(this).find('tr') to get all tr from the selected table
$(this).find("tr").each(function() {
$this = $(this)
var email = $this.find("textarea").val();
var frequency = $this.find("select").val();
alert(email + '--' + frequency);
});
});
});
或作爲建議由Rune
$("#btnSave").click(function() {
$(".templateTable tr").each(function() {
$this = $(this)
var email = $this.find("textarea").val();
var frequency = $this.find("select").val();
alert(email + '--' + frequency);
});
});
0
this "tr.item"
是不是真正的選擇者。
你需要把它們分成兩個單獨的鏈接選擇:
$(this).find("tr.item")
0
相關問題
- 1. 循環遍歷列表對的元素
- 2. ASP循環遍歷表單元素
- 3. 循環遍歷集合的元素
- 4. jQuery循環遍歷DIV中的元素
- 5. 循環遍歷變量中的元素
- 6. 循環遍歷多個列表 - Python
- 7. 使用VBA循環遍歷DIV元素
- 8. for循環 - 遍歷特定元素
- 9. jQuery的:循環遍歷元素和數量的孩子
- 10. 多次循環遍歷DataTable
- 11. 循環遍歷表中的所有td元素
- 12. 如何循環遍歷表單中的所有元素jQuery
- 13. 循環遍歷jQuery中的類型圖表元素
- 14. 循環遍歷表列
- 15. Python循環遍歷列表
- 16. 循環遍歷關係表
- 17. 循環遍歷錶行
- 18. 循環遍歷錶行
- 19. Jquery循環遍歷錶行
- 20. Angularjs循環遍歷表
- 21. MySQL循環遍歷表
- 22. Django循環遍歷列表
- 23. Swift循環遍歷列表
- 24. 循環遍歷元素並添加一個遞減的z-index
- 25. 如果語句循環遍歷Python中的單個元素
- 26. jquery遍歷子元素
- 27. 循環遍歷多個標籤數組
- 28. 一次循環遍歷多個數字
- 29. Python BeautifulSoup - 循環遍歷多個頁面
- 30. 如何在一個時間循環遍歷數組中的多個元素
第二個'each'不是必須的,你可以使用'.templateTable tr'。檢查[這個小提琴](http://jsfiddle.net/7aDak/933/)。這將節省大量不需要的數據。 –