2013-07-27 78 views
0

我使用panelbar,從而形成標籤被擾亂它的開放/關閉動畫轉換/更改Div元素

我發現form標記創建的問題,所以我想div標籤轉換成標籤當我點擊提交按鈕。

如:

<div class="myForm"> 
<div id="detail"> 
    Name: <input type="text" name="text_name" value="Some text here to edit"/> 
</div> 
<div id="income"> 
    Income: <input type="text" name="text_income" value="your income"/> 
</div> 
    <input type="submit" value="Submit" /> 
</div> 

轉換爲:

<form name="input" id="" action="html_form_action.php" method="post"> 
<div id="detail"> 
    Name: <input type="text" name="text_name" value="Some text here to edit"/> 
</div> 
<div id="income"> 
    Income: <input type="text" name="text_income" value="your income"/> 
</div> 
    <input type="submit" value="Submit" /> 
</form> 

所以,我要的是改變分度類「.myForm」形成元素 和關閉分度結束表單標籤。

有沒有辦法做到這一點?

+0

u能股利前加表單元素.... –

回答

3

使用JavaScript + jQuery的:

$('.myForm').children().unwrap().wrapAll("<form name='input' id='' action='html_form_action.php' method='post'></form>"); 

這消除了包裝格 「.myForm」 與unwrap方法。然後用wrapAll方法包裝它的孩子。

+0

不確定爲什麼這已經downvoted。它確實是OP想要的。對手回答者? – shennan

0

如果你喜歡html5,你可以查看html5的「form Attribute」,它允許你隨意使用表單元素,而且你不需要將表單元素包裝在表單標籤中。

檢查了這一點

<form name="input" id="myform" action="html_form_action.php" method="post"></form> 

<div class="myForm"> 
    <div id="detail"> 
     Name: <input type="text" name="text_name" value="Some text here to edit" form="myform" /> 
    </div> 
    <div id="income"> 
     Income: <input type="text" name="text_income" value="your income" form="myform" /> 
    </div> 
    <input type="submit" value="Submit" form="myform" /> 
</div> 
1

可以完成這項工作簡單地使用jQuery -

$(document).ready(function(){  
    $('form').html($('.myForm').html()); 
}); 

但是,如果你想這樣做,因爲你使用分配一些元素的id這是不正確的。因此,將整個HTML附加到<form>之後,您應該刪除.myForm

Try This

對於刪除的div with class .myForm追加innerhtml成表格後,你可以簡單地使用.remove

$(document).ready(function(){  
     $('form').html($('.myForm').html()); 
     $('.myForm').remove(); 
    }); 

Try This