2013-04-18 32 views
3

我有一個div,其中我已經放置了我的textarea提交按鈕。我需要在每個帖子下放置textarea,讓用戶發表評論。表單提交使用jquery移動div後無法工作

這裏是我的textarea

<div id="textarea_wrap"> 
    <div id="textarea_12" class="txtarea"> 
    <form name="post_comment" action="reply.php" method="post"> 
    <input type="hidden" name="post_title" value="Post Title" /> 
    <input type="hidden" name="post_id" value="12455" /> 
    <textarea class="textarea" id="txt_12"></textarea> 
    <input type="submit" class="button" value="Submit Comment /> 
    </form> 
    </div> 
</div> 

的形狀,當我DIV textarea_wrap的innerHTML和使用jQuery將其移動到一些其他分區,它停止工作。

例如

var txtarea = $("#textarea_wrap").html(); 
    $("#comment_10").html(txtarea); 

它移動textarea_wrap div的內部HTML到#comment_10 div成功,當我查看源使用jQuery它看起來像這樣

<div id="comment_10"> 
    <div id="textarea_12" class="txtarea"> 
    <form name="post_comment" action="reply.php" method="post"> 
    <input type="hidden" name="post_title" value="Post Title" /> 
    <input type="hidden" name="post_id" value="12455" /> 
    <textarea class="textarea" id="txt_12"></textarea> 
    <input type="submit" class="button" value="Submit Comment /> 
    </form> 
    </div> 
</div> 

移動DIV之後,但它不工作,當我點擊「提交評論」按鈕時,沒有任何反應。如果我使用此代碼而不通過jquery,它可以正常工作。無法理解,爲什麼它不通過jquery後移動。

+0

您是否使用任何javascript/jquery提交表單 – bipen

回答

0

不知道though..check,看看你是否可以這樣

$('.button').live('click',function({ 
    $('#give your form Id').submit(); 
}); 
2

提交鑑於已克隆形式爲前具有相同的名稱,當您嘗試這將創建一個錯誤的DOM提交表格。

建議:每次克隆時都要更改表格名稱。

解決方案(jQuery的):

var txtarea = $("#textarea_wrap").html(); 
$("#comment_10").html(txtarea); 

var txtarea = $("#textarea_wrap").html(); 
$("#comment_10").html(txtarea).find('form').attr('name','post_comment'+(Math.floor(Math.random()*10000))); 
0

這兩種形式都具有相同的名稱 「post_comment」。表單名稱應該是唯一的。

0

這可能是也可能不是問題的一部分,但是在提交按鈕定義中存在語法錯誤。請記住關閉值屬性的報價value =「提交評論