我想用 Javascript 循环遍历一个表单,但我的问题是第一个表单中有另一个表单。
我只想循环第一个表单,而不是内部表单。我在另一篇文章中找到了这个方法:
var table = $("#table_cultures tbody");
table.find('tr').each(function (i) {
var $tds = $(this).find('td'),
productId = $tds.eq(0).text(),
product = $tds.eq(1).text(),
Quantity = $tds.eq(2).text();
// do something with productId, product, Quantity
alert('Row ' + (i + 1) + ':\nId: ' + productId
+ '\nProduct: ' + product
+ '\nQuantity: ' + Quantity);
});
此方法有效,但会循环两种形式。
编辑 1:
html 看起来像:
<form>
<table>
<tr>
<td>Something here</td>
</tr>
<tr>
<td>
<form>
<table>
//tr td ...
</table>
</form>
</td>
</tr>
</table>
</form>
最佳答案
<form>
的嵌套不允许使用元素
请参阅: https://www.w3.org/TR/html5/forms.html#the-form-element
"...Flow content, but with no form element descendants..."
关于javascript - 循环遍历包含另一个表单的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37271020/