【问题标题】:Jquery remove form tag, not contentJquery删除表单标签,而不是内容
【发布时间】:2020-02-19 17:55:12
【问题描述】:

您好,我需要删除一个表单标签,但不是内容:

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

</form>

【问题讨论】:

    标签: jquery


    【解决方案1】:
    $form = $('#form');
    $form.replaceWith($form.html());
    

    应该做你需要的。

    【讨论】:

      【解决方案2】:

      为你的 div 添加一个 id 或类

      例如

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

      然后

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

      【讨论】:

        【解决方案3】:

        当您从 DOM 中删除表单标签时,它的所有子元素都会随之而来。实现您所要求的唯一方法是提取所有表单标签的直接子级并将它们附加到 DOM 中的某个其他节点,以防止它们从页面中消失

        【讨论】:

          【解决方案4】:

          如果你有很多元素需要修改:

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

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

          【讨论】:

            【解决方案5】:
            $('.element').replaceWith(function() {
            

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

            这是错误的......

            $form = $('#form');
            

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

            这个是对的……

            【讨论】:

            • 你能解释一下为什么一个是正确的而另一个不是吗?
            【解决方案6】:

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

            【讨论】:

              猜你喜欢
              • 2012-04-08
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2017-11-16
              • 2012-09-29
              • 1970-01-01
              • 2016-04-16
              • 2012-11-12
              相关资源
              最近更新 更多