0
$("body").delegate(".u-post-button", "click", function(){
var btn = $(this);
var currentPost = btn.parents('.content-event');
var content = btn.siblings('textarea[name="comment-post-content"]').val();
if (content)
{
var event_id = currentPost.find('.event-id').val();
var url= '/post-comments/'+event_id +'/';
content: content
}
$.post(url , data, function(data){
var obj = $.parseJSON(data);
var lang = '';
$.each(obj, function() {
lang += this['html'];
});
$(currentPost.find('.latest-comment')).append(lang);
$(currentPost.find('.comment-post-content')).val("");
});
}
else
{
$(currentPost.find('.comment-post-content')).attr("rows", "1");
}
return false;
});
這是腳本發佈評論,然後將返回的json放在「.latest-comment」div之後。它工作正常,但評論順序是從最古老到最新的,因爲我們往下走。我想相反。我怎樣才能做到這一點?我嘗試使用prependTo代替追加,但是,然後評論不會顯示。這是HTML,按時間順序添加新divs [jQuery]
<div class="content-event">
<form method="post">
{% csrf_token %}
<textarea class="comment-post-content" name="comment-post-content" cols="55" rows="1" placeholder="Add a comment..."></textarea>
<input type="hidden" class="event-id" value="{{ event.id }}">
<input type="submit" class="u-post-button" value="Post comment" />
</form>
</div>
<div class="latest-comment"></div>
發表您的HTML過,如果可能創造的jsfiddle ......將有助於調試 – iJade