javascript - 使用 jQuery 删除表但不删除表单和字段

标签 javascript jquery html

我在表中有一个 HTML 表单 我想完全摆脱那个表并想在 中添加 formfields >div 我想用 jQuery 做到这一点 任何机构都有办法做到这一点吗? 这是我当前的代码。

<div class="widgetGuts shortcode">
    <form action="" method="post" id="frm-subscriptionFront" novalidate="">
        <table>
            <tbody>
                <tr class="required">
                    <th>
                        <label for="frm-email" class="required"></label>
                    </th>
                    <td>
                        <input type="text" name="email" id="frm-email" required="" value="" class="text form-control" placeholder="Enter your email address here">
                    </td>
                </tr>
                <tr>
                    <th></th>
                    <td>        
                        <input type="submit" name="_submit" class="subscribeButton button" value="Subscribe">
                    </td>
                </tr>
            </tbody>
        </table>

        <div>
            <input type="hidden" name="_form_" value="subscriptionFront">
            <!--[if IE]>
                <input type=IEbug disabled style="display:none">
            <![endif]-->
        </div>
    </form>
</div>

这是我想要的代码示例。

<div class="widgetGuts shortcode">
    <form action="" method="post" id="frm-subscriptionFront" novalidate="">
        <input type="text" name="email" id="frm-email" required="" value="" class="text form-control" placeholder="Enter your email address here">
        <input type="submit" name="_submit" class="subscribeButton button" value="Subscribe">
        <div>
            <input type="hidden" name="_form_" value="subscriptionFront">
            <!--[if IE]>
                <input type=IEbug disabled style="display:none">
            <![endif]-->
        </div>
    </form>
</div>

最佳答案

$('#frm-subscriptionFront table').replaceWith( $('td > *, th > *') );

http://jsfiddle.net/ptapy47b/1

编辑澄清:它将用 tdth 元素的内容替换表格,因此表格中的所有元素最终都会出现在您的表单中,而不是只是 input 元素。这是 IMO 的好主意。

关于javascript - 使用 jQuery 删除表但不删除表单和字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28172193/

相关文章:

javascript - "How to ' 重新加载唯一的局部 View ' part after submitting the form with HTML Helper in jquery?"

javascript - Fancybox (jQuery) - 将信息从父级传递到 iframe,然后将 iframe 传回父级

javascript - 如何修复 body-parser 不解析 express NodeJS 中的 html 表单日期输入字段?

javascript - react-redux/react-router 连接和 withRouter 函数的 ownProps 参数的 PropTypes?

javascript - 如何在一个窗口中为不同页面设置一次变量

javascript - 在 html 中用 1 个按钮隐藏/显示多个对象

javascript - 如何在 ruby​​ on Rails 中将文本值迭代为 Active Record 模型名称格式?

javascript - chart.js 图形上的偏移叠加线

html - 带水平滚动的 DIV - Bootstrap 4

javascript - ng-show 在隐藏之前是可见的