2011-11-17 50 views
-2

可能重复:
Clone a <form></form> tag and wrap it around existing content?解开form标签

这是从萤火虫主HTML结构。我没有包含任何内容或任何内容,因为它的内容很多。我问了一个类似的问题,但没有奏效。我希望我能得到以下工作。我需要“解开”你看到的FORM标签,但是保留它里面的任何内容。然后我需要采用相同的FORM标签,并使其环绕在< DIV ID =“TOP_NAV”>下方的表格中。

<div id="content"> 
<div id="top_nav"> 
<table cellspacing="0" cellpadding="0" border="0"> 
<tbody> 
<tr> 
<td id="nav_menu" class="bgcolor2 colors_background2 colors_background2_text" valign="top"> 
<td id="main_content" valign="top"> 
<script type="text/javascript"> 
<div id="content_area"> 
<script type="text/javascript"> 
<script src="https://stackoverflow.com/a/j/product_details.js" type="text/javascript"> 
<script src="https://stackoverflow.com/a/j/product_details.js" type="text/javascript"> 
<script type="text/javascript"> 
<form id="vCSS_mainform" onsubmit="javascript:return QtyEnabledAddToCart_SuppressFormIE();" action="/ProductDetails.asp?ProductCode=40124" name="MainForm" method="post"> 
<span class="PageText_L493n"></span> 
<br> 
</div> 
</td> 
</tr> 
</tbody> 
</table> 
</div> 
+0

对不起,我迷路了....解开表格标签!??!?!?! – ManseUK

+0

和...什么? – GolezTrol

+0

有一个

内容
标记。我需要采取只是
标签,并将其移动到其他地方。 – user985952

回答

0

我想这个代码会为你做的工作。它可能会进行优化,我刚刚实施了解决方案,并将优化留给您。

// create a clone of the form element 
    var cloneForm = $("#vCSS_mainform").clone(); 

    // move the contents of the form to the outside div 
    $("#content_area").html(cloneForm.html()); 

    // replace the contents of the form with the contents of top_nav div 
    cloneForm.hide().html($("#top_nav").html()); 

    // set the top_nav div to contain the form and form's contents 
    $("#top_nav").html(cloneForm); 

    // show the form 
    cloneForm.show();