2012-10-11 34 views
0

我正在php,jquery中實現註釋系統。我列出了我需要打開父母評論下的回覆表單或框的評論。我的代碼如下如何使用jQuery在父註釋下打開回復框

HTML代碼

<div id="record-1" class="friends_area"> 
    <a href="javascript:;"> 
     <img width="40" height="40" border="0" alt="" style="float:left; padding-right:9px;" src=""> 
    </a> 
    <label class="name" style="float:left; width:390px;"> 
     <span> 
      <span style="padding-left:10px;"> 59 minutes ago </span> 
      <br clear="all"> 
      <div class="name" style="text-align:justify;float:left;"> 
       <em> Dsffdfdfd</em> 
       <br clear="all"> 
       <div style="height:10px;"> 
        <a id="post_id1" class="showCommentBox" href="javascript: void(0)">Reply</a> 
        - 
        <span id="like-panel"> </span> 
       </div> 
      </div> 
    </label> 
    <a class="delete_p" href="#" style="color:#ff0000;"> Image </a> 
    <br clear="all"> 
    <div id="CommentPosted1"> 
     <div id="loadComments1" style="display:none"></div> 
    </div> 
    <div id="commentBox-1" class="commentBox" align="right" style="display:none"> </div> 
</div> 
<div id="record-1" class="friends_area"> 
    <a href="javascript:;"> 
     <img width="40" height="40" border="0" alt="" style="float:left; padding-right:9px;" src=""> 
    </a> 
    <label class="name" style="float:left; width:390px;"> 
     <span> 
      <span style="padding-left:20px;"> 59 minutes ago </span> 
      <br clear="all"> 
      <div class="name" style="text-align:justify;float:left;"> 
       <em> Dsffdfdfd</em> 
       <br clear="all"> 
       <div style="height:20px;"> 
        <a id="post_id2" class="showCommentBox" href="javascript: void(0)">Reply</a> 
        - 
        <span id="like-panel"> </span> 
       </div> 
      </div> 
    </label> 
    <a class="delete_p" href="#" style="color:#ff0000;"> Image </a> 
    <br clear="all"> 
    <div id="CommentPosted2"> 
     <div id="loadComments2" style="display:none"></div> 
    </div> 
    <div id="commentBox-2" class="commentBox" align="right" style="display:none"> </div> 
</div> 
    My Reply Box 
<div id="replymsgbox" style="display: none;"> 
    <form id="frmComment" novalidate="novalidate" method="POST" name="frmComment"> 
     <div> 
      <textarea id="comment_text" class="" name="comment[text]"></textarea> 
      <div id="error_text"> </div> 
     </div> 
     <div>   
      <input type="hidden" value="0" name="Parent_id" id=""Parent_id>    
      <input type="submit" value="Post" name="Submit"> 
     </div> 
    </form> 
</div> 

我的Jquery:

//showCommentBox 
$('a.showCommentBox').livequery("click", function(e){ 

var getpID = $(this).attr('id').replace('post_id',''); 

$('#replymsgbox', $(this).parents().next()).slideToggle('fast') 

}); 

任何援助表示讚賞!

回答

3

你需要在.parents()中指定一個選擇器,否則它不會返回任何東西。 或者你可以簡單地使用.parent()如果你想訪問元素的直接父母。

文檔是here

而且,由於你使用.livequery,我猜想那是因爲你正在使用the plugin,不想使用默認.click().live()方法。