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

标签 javascript html

我想用 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/

相关文章:

javascript - 每次调用时在 sinon 中插入一个函数以返回不同的值

javascript - 我怎样才能摆脱这段代码中的重复

html - 嵌入响应式 WordPress 网站时如何使 Marketo 表单响应?

javascript - 获取提交类型以发布其值

php - 使用 htmlspecialchars() 和使用 mysqli 时不显示重音

javascript - AngularJS - 范围未应用于 Controller 功能内的 View

javascript - AngularJs模板和内容共享

javascript - 将数据从 php 发送到 javascript

javascript - 为什么在结束上下文之前评估动态内联脚本标记?

jquery - 单个 jQuery 函数单独切换多个元素