繁体   English   中英

如何使用jQuery在父注释下打开回复框

[英]How to open reply box under parent comments using jQuery

我在php,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')

});

任何帮助表示赞赏!

您需要在.parents()指定选择器,否则它将不返回任何内容。 或者,如果您想访问元素的直接父级,则可以简单地使用.parent()

文档在这里

另外,由于您使用的是.livequery ,因此我假设这是因为您使用的是插件,并且不想使用默认的.click().live()方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM