Jquery删除表单标记,而不是内容

时间:2009-10-22 16:52:39

标签: jquery

您好我需要删除表单标记但不删除内容:

<form id="form">
<div> not remove this only the form tag</div>

</form>

6 个答案:

答案 0 :(得分:26)

$form = $('#form');
$form.replaceWith($form.html());

应该做你需要的。

答案 1 :(得分:2)

在div中添加id或类

e.g。

<form id="form">
<div class="wrapper"> not remove this only the form tag</div></form>

然后

$(".wrapper").unwrap();

答案 2 :(得分:0)

从DOM中删除表单标记时,其所有子元素都会正确显示。您可以实现所要求的唯一方法是拉出所有表单标记的直接子节点,并将它们附加到DOM中的其他节点,以防止它们从页面中消失

答案 3 :(得分:0)

如果您有许多需要修改的元素:

$('.element').replaceWith(function() {
  return $(this).html();
});

jsFiddle:http://jsfiddle.net/calvintennant/mdrHb/

答案 4 :(得分:0)

$('.element').replaceWith(function() {

返回$(this).html(); });

这是错误的......

$form = $('#form');

$ form.replaceWith($ form.html());

这是正确的...

答案 5 :(得分:-2)

如果它是xml(由dotNet生成的页面),只需删除表单节点

相关问题