【发布时间】:2020-02-19 17:55:12
【问题描述】:
您好,我需要删除一个表单标签,但不是内容:
<form id="form">
<div> not remove this only the form tag</div>
</form>
【问题讨论】:
标签: jquery
您好,我需要删除一个表单标签,但不是内容:
<form id="form">
<div> not remove this only the form tag</div>
</form>
【问题讨论】:
标签: jquery
$form = $('#form');
$form.replaceWith($form.html());
应该做你需要的。
【讨论】:
为你的 div 添加一个 id 或类
例如
<form id="form">
<div class="wrapper"> not remove this only the form tag</div></form>
然后
$(".wrapper").unwrap();
【讨论】:
当您从 DOM 中删除表单标签时,它的所有子元素都会随之而来。实现您所要求的唯一方法是提取所有表单标签的直接子级并将它们附加到 DOM 中的某个其他节点,以防止它们从页面中消失
【讨论】:
如果你有很多元素需要修改:
$('.element').replaceWith(function() {
return $(this).html();
});
【讨论】:
$('.element').replaceWith(function() {
返回 $(this).html(); });
这是错误的......
$form = $('#form');
$form.replaceWith($form.html());
这个是对的……
【讨论】:
如果是xml(如dotNet生成的页面),只需删除表单节点
【讨论】: