我在表中有一个 HTML
表单 我想完全摆脱那个表并想在 中添加
我想用 jQuery 做到这一点 任何机构都有办法做到这一点吗?
这是我当前的代码。form
和 fields
>div
<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
编辑澄清:它将用 td
和 th
元素的内容替换表格,因此表格中的所有元素最终都会出现在您的表单中,而不是只是 input
元素。这是 IMO 的好主意。
关于javascript - 使用 jQuery 删除表但不删除表单和字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28172193/