使用jQuery删除第二个表单元素而不丢失子元素

Tor*_*ups 2 javascript jquery

我有一些AJAX工作带来了我在DOM中不需要的额外表单元素.我没有能力删除它的服务器端,所以我正在寻找一些jQuery或经典JavaScript,它将允许我捕获表单中的所有子元素,删除我不需要的表单,最后重新将子元素追加回DOM.

任何帮助将非常感激

编辑:感谢您的快速解答,以下是我实际使用的,它的工作完美

            // Captures the children
            var children = $("form:eq(1)").children();
            // Removes the form
            $("form:eq(1)").remove();
            // append the child elements back into the DOM 
            $("#fillDiv").append(children);
Run Code Online (Sandbox Code Playgroud)

Pre*_*aul 6

.html()您应该移动子节点,而不是使用该方法(这将导致您丢失与表单元素关联的任何事件):

// grab the child nodes
var children = $('#badForm').children();
// or var children = $('#badForm > *');

// move them to the body
$(body).append(children);

// remove the form
$('#badForm').remove();
Run Code Online (Sandbox Code Playgroud)