我现在使用的代码只是克隆了“.comment_post” div 并将表单插入到评论下方。
我想做的(如果可能的话)是将“.comment_post”div“移动”到新位置而不是克隆它。
关于如何做到这一点的任何建议?
HTML
<div class="comment-post">
<form id="addCommentForm" method="post" action="">
<div class="avatar"><img src="http://www.gravatar.com/avatar/ee61e6c16/?s=36&r=g&d=mm" /></div>
<textarea name="txt" id="txt" class="txtcomment"></textarea><button class="btnComment" type="button">Send</button>
</form></div>
<div class="comment">
<span class="avatar"><img src="http://www.gravatar.com/avatar/ee61e6c16/?s=36&r=g&d=mm"></span>
<span class="poster">Jake</a></span><span class="time">5 months ago</span>
<div class="text">just a test comment ...</div>
<div class="reply"><a href="#" onclick="reply(174);">Reply</a></div><div id="new-174"></div>
</div>
<div class="comment">
<span class="avatar"><img src="http://www.gravatar.com/avatar/ee61e6c16/?s=36&r=g&d=mm"></span>
<span class="poster">Jake</a></span><span class="time">5 months ago</span>
<div class="text">another comment ...</div>
<div class="reply"><a href="#" onclick="reply(175);">Reply</a></div><div id="new-175"></div>
</div>
JS
reply = function(id){
if(!$('#new-'+id+' .comment-post').length) {
$('.comment-post:first').clone().attr('id', id).appendTo($('#new-'+id));
$('#new-'+id+' .txtcomment').focus();
$('#new-'+id+' .txtcomment').autosize();
$('#new-'+id+' .txtcomment').bind('keydown', charcounter);
$('#new-'+id+' .txtcomment').bind('keyup', charcounter);
}
else
{
$('#new-'+id+' .comment-post').remove();
}
}