2011-10-10 77 views
1

現在我有ClipBucket,並且正在編輯它的註釋部分。JQuery .fadein()數據插入頂部而不是底部

當發表評論時,新評論顯示在列表的底部,它需要在發佈時顯示在頂部。

var formObjectData = $('#'+form_id).serialize()+'&mode=add_comment'; 

$.post(page,formObjectData, 
    function(data) 
    { 
     if(!data) 
      alert("No data"); 
     else 
     { 

      $("#add_comment_button").attr("disabled",""); 

      $("#add_comment_result").css("display","block"); 
      if(data.err!='') 
      { 
       $("#add_comment_result").html(data.err); 
      } 
      if(data.msg!='') 
       $("#add_comment_result").html(data.msg); 

      if(data.cid) 
      { 
       get_the_comment(data.cid,"#latest_comment_container"); 
       $("#"+form_id).slideUp(1500).delay(10000).fadeIn(1500).val(""); 
      } 
     } 
    },'json'); 
} 

function get_the_comment(id,div) 
{ 

    $(div).html(loading); 
    $.post(page, 
    {  
     mode : 'get_comment', 
     cid : id 
    }, 
    function(data) 
    { 
     if(!data) 
      alert("No data"); 
     else 
     {   
      $(div).css("display","none"); 
      $(div).html(data).fadeIn("slow"); 
     } 
    },'text'); 
} 

此外,在這裏我也行:

$("#"+form_id).slideUp(1500).delay(10000).fadeIn(1500).val("");" 

有什麼我可以添加到這個講清楚,並重置表單?它顯示的是舊文本的備份,如果有新的評論出現,它只是編輯第一個,即使它發佈了新的評論。

此外,有沒有一個按鈕,我可以添加,將刷新評論列表,而無需刷新頁面?

HTML:

`comments.html 
{if $comments} 
<div style="height:10px"></div> 
    {foreach from=$comments.comments item=comment} 
     {include file="$style_dir/blocks/comments/comment.html" comment=$comment type=$type parents=$comments.parents} 
    {/foreach} 

    <div style="height:10px"></div> 


{else} 
    <div id="latest_comment_container"> 
    <div align="center" class="no_comments"> 
     {lang code='no_comments' assign=no_comments} {$no_comments|sprintf:$object_type} 
    </div> 
    </div> 

{/if} 
{if $comments} 
<div id="latest_comment_container"></div> 
{/if} 


add_comment.html: 
<div class="add_comment_box" id="add_comment"> 
<h2 style="margin:0px">{lang code='grp_add_comment'}</h2> 


<div id="add_comment_result" class="add_comment_result" style="display:none"></div> 
{if $userquery->login_check('',true) || $Cbucket->configs.anonym_comments == 'yes'} 
<form name="comment_form" method="post" action="" id="comment_form" value="0"> 
    <input type="hidden" name="reply_to" id="reply_to" value="0"> 
    <input type="hidden" name="obj_id" id="obj_id" value="{$id}"> 

    {if !$userquery->login_check('',true) && $Cbucket->configs.anonym_comments == 'yes'} 
    <label for="name" class="label">{lang code='name'}</label> 
    <br> 
    <input type="text" name="name" id="name" class="input"><br> 
    <label for="email" class="label">{lang code='email_wont_display'}</label> 
    <br> 
    <input type="text" name="email" id="email" class="input"><br> 
    {else} 
    Name : {$userquery->username}<br> 
    {/if} 

    {ANCHOR place='before_compose_box'} 
    <textarea name="comment" id="comment_box" cols="45" rows="5" class="input" style="width:97%" ></textarea> 

    <div style="height:10px"></div> 


     {if config('comments_captcha')=='all' || (config('comments_captcha')=='guests' && !$userquery->login_check('',true))} 

     <div style="width:auto; float:left; "> 
    <strong>{lang code='please_enter_confimation_ode'}</strong> 

     {assign var=captcha value=func->get_captcha()} 
     {if $captcha} 
      {if $captcha.show_field} 
       <label class="label" for="captcha">Verification Code</label><br /> 
        {load_captcha captcha=$captcha load=field field_params = ' id="captcha" class="input" '} 
       <div class="clearfix"></div> 
      {/if} 
      <label class="label">&nbsp;</label> 

       {load_captcha captcha=$captcha load=function} 

      <div class="clearfix"></div> 
     {/if} 

     </div> 
    {/if} 

    <div style="width:auto; float:left;padding-left:10px; padding-bottom:10px">{ANCHOR place='after_compose_box'}</div> 

    <div class="clear"></div> 

    <input type="hidden" name="type" value="{$type}" /> 
    <div style="margin-top:2px" ><input type="button" name="add_comment" id="add_comment_button" value="{lang code='user_add_comment'}" 
    class="cb_button" onclick="add_comment_js('comment_form','{$type}'){ANCHOR place='onClickAddComment'}"></div> 
<div style="margin-top:2px" ><input type="button" name="reload" id="reload_comment_button" value="Reload" 
    class="cb_button" onclick="reload_comment_js('comment_form','{$type}'){ANCHOR place='onClickAddComment'}"></div> 
</form> 
{else} 
    {lang code='please_login_to_comment'} 
{/if} 
</div> 

comment.html: 
{if marked_spammed($comment)} 
    {assign var='comment_attr' value='style="display:none"'} 
    {assign var='spam_attr' value='style="display:block"'} 
{else} 
{assign var='comment_attr' value=''} 
    {assign var='spam_attr' value='style="display:none"'} 
{/if} 

    <div id="comment_{$comment.comment_id}" class="comment clearfix" {$comment_attr}> 
    <div class="user_com_thumb_con"> 
     <img src="{$userquery->getuserthumb($comment)}" class="user_com_thumb" /> 
    </div> 
    <div class="comm_other"> 
     <div class="user_bar"> 
     <div style="width:70%; float:left"> 
     {lang code='user_commented_time' assign='user_commented_time'} 
     {assign var="nicetime" value=$comment.date_added|niceTime} 
     {if $comment.userid !='' && $comment.userid!=0} 
      {assign var="comm_link" value=$userquery->profile_link($comment)} 
      {assign var="comm_owner" value=$comment.username} 
     {else} 
      {assign var="comm_id" value="#comment_"} 
      {assign var="comm_link" value=$comment.comment_id} 
      {assign var="comm_owner" value=$comment.anonym_name}  
     {/if} 

     {$user_commented_time|sprintf:"$comm_id$comm_link":$comm_owner:$nicetime} 

     </div> 
     <div style="width:28%; float:right" align="right"><a href="javascript:void(0)" onclick="to_reply('{$comment.comment_id}')">{lang code='reply'}</a> | <a href="javascript:void(0)" onclick="spam_comment('{$comment.comment_id}','{$type}','{$type_id}')">{lang code='spam'}</a> 

     {if has_access('admin_del_access') || $comment.userid==userid() || $comment.type_owner_id==userid()} | <a href="javascript:void(0)" onclick="delete_comment('{$comment.comment_id}','{$type}','{$type_id}')">{lang code='delete'}</a>{/if}</div> 
     </div> 

     <div class="comment_cont"> 

     {if $comment.parent_id} 
      {assign var=parentid value=$comment.parent_id} 
      {assign var=thisParent value=$parents.$parentid} 

      {if $thisParent} 
      <div style="padding:3px; margin:5px; background-color:#CCC"> 

       {if $thisParent.username}@{$thisParent.username} : 
       {/if}{$thisParent.comment|comment} 
      </div> 
      {/if} 
     {/if} 

     {$comment.comment|comment} 

     </div> 

     {if $type=='video' && $comments_voting=='yes' && $Cbucket->configs.comment_rating} 
     <div class="comment_rating_cont"><span class="thumb_up" onclick="rate_comment('{$comment.comment_id}','up','{$type}','{$type_id}')">Thumbs Up</span><span class="thumb_down" onclick="rate_comment('{$comment.comment_id}','down','{$type}','{$type_id}')">Thumbs Down</span><span id="comment_rating_{$comment.comment_id}" class="comment_rating">{$comment.vote|comment_rating}</span></div> 
     {/if} 

    </div> 
    </div> 

    <div id="spam_comment_{$comment.comment_id}" class="spam" {$spam_attr} > 
     {lang code='marked_as_spam_comment_by_user' assign='marked_as_spam_comment_by_user'} 

     {if $comment.username}{$marked_as_spam_comment_by_user|sprintf:$comment.username}{else}{$marked_as_spam_comment_by_user|sprintf:$comment.anonym_name}{/if} | <a href="javascript:void(0)" onclick="delete_comment('{$comment.comment_id}')">{lang code='delete'}</a> 
    </div>` 
+1

只是我的意見,但你應該避免混合空間分隔'if'聲明當它具有多行的「else」時(並且需要大括號)。 –

+0

我沒有寫它,只是添加了一行我引用下面我粘貼的代碼。 –

回答

1

,如果你希望在每次新的評論被提交時添加的內容看看.prepend().append()

With .load()您可以加載例如在一個div一個文件:

$('#selector').load('comments.php'); 

編輯:

前面加上評論:例如爲:#comments是你的DIV所有您的意見所示。在這種情況下,每個評論都有它自己的分類.comments_box。現在每添加一條評論,您都會在#comments前添加一個新評論框。

$('#comments').prepend('<div class="comments_box">' + data + '</div>'); 

重裝評論:例如爲:在你的DIV #comments你包括文件comments.php<?php include('comments.php'); ?>)。現在要重新加載(或簡單地加載)的comments.php再次在div #comments當你點擊類.reload

$('.reload').click(function() { 

    $('#comments').load('comments.php'); 

}); 
+0

我在這裏完全是綠色..你能描述更多嗎? –

+0

我不知道在哪裏嘗試使用該代碼。 –

+0

你可以發佈html嗎? – Fabian

相關問題