循环遍历包含另一个表单的表单

Loop through a form which contains another form

本文关键字:表单 另一个 包含 遍历 循环      更新时间:2023-09-26

我想用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-表单元素

"…流动内容,但没有表单元素子体…"