简体   繁体   English

如何在多个显示的评论上显示/隐藏回复评论框

[英]how to show/hide reply comment box on multiple displayed comments

so here is the code i use this for me to show/hide the comment box it works actually but the problem i encounter when i make multiple comments when i tried to click the reply on the 1st comment the comment box show/hide but when i tried to click other comments it doesnt work anymore it only works on the first one.... is there any way to fix this?.. 所以这是我用来显示/隐藏评论框的代码,它实际上有效,但是当我尝试单击第一个评论的回复时,我做出多个评论时遇到的问题是显示/隐藏评论框试图单击其他评论,它不再起作用了,它只能在第一个评论上起作用。...有什么办法可以解决这个问题?

HTML code HTML代码

<div id="replybutton" class="btn4 like" style="margin-top:-25px;margin-left:-10px;">
    <span class="btn reply" id="replyb">Reply</span> •&emsp;
</div>

<div class="col-lg-12" id="reply" style="background:#eff9c7;margin-left:50px;margin-top:-20px;display:none;" >
    <img  src="img/icons/no-icon-available.png" class="pull-left" style="   border-radius:50%;margin-bottom:3px;width:30px;height:30px;" />
    <p style="margin-top:18px;line-height:15px;"><strong class="font-1" style="margin-left:10px;">Hajime Sasota </strong> Sample comment<br>

<div class="btn4 disabled" style="margin-top:-25px;margin-left:-10px;">
    <span style="margin-left:5px;font-size:12px;color:gray;"><abbr class="timeago" title="">time</abbr></span>
</div>
</p>
<input type="text" class="form-control pull-right" style="width:88%;height:25px;margin-top:-10px;" placeholder="Write a reply..." />
</div>

JAVASCRIPT JAVASCRIPT

<script type="text/javascript">
$(document).ready(function(){
$('#replybutton').click(function(){
$('#reply').toggle();
});
});
</script> 

id must be unique in a HTML Page, you should change id to class replybutton and reply and jquery code would be, id在HTML页面中必须是唯一的,您应该将id更改为类replybutton然后reply和jquery代码将是,

$(document).ready(function(){
    $('.replybutton').click(function(){
       $(this).next('.reply').toggle();
    });
});

Snippet, 片段

 $(document).ready(function() { $('.replybutton').click(function() { $(this).next('.reply').toggle(); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div class="container"> <div class="replybutton btn4 like" style=""> <span class="btn reply" id="replyb">Reply</span> •&emsp; </div> <div class="col-lg-12 reply" style="display:none"> <img src="img/icons/no-icon-available.png" class="pull-left" style="" /> <p> <strong class="font-1" style="margin-left:10px;">Hajime Sasota </strong> Sample comment<br/> <div class="btn4" style=""> <span style=""><abbr class="timeago" title="">time</abbr></span> </div> </p> <input type="text" class="form-control pull-right" placeholder="Write a reply..." /> </div> </div> <div class="container"> <div class="replybutton btn4 like" style=""> <span class="btn reply" id="replyb">Reply</span> •&emsp; </div> <div class="col-lg-12 reply" style="display:none"> <img src="img/icons/no-icon-available.png" class="pull-left" style="" /> <p> <strong class="font-1" style="margin-left:10px;">Hajime Sasota </strong> Sample comment<br/> <div class="btn4" style=""> <span style=""><abbr class="timeago" title="">time</abbr></span> </div> </p> <input type="text" class="form-control pull-right" placeholder="Write a reply..." /> </div> </div> <div class="container"> <div class="replybutton btn4 like" style=""> <span class="btn reply" id="replyb">Reply</span> •&emsp; </div> <div class="col-lg-12 reply" style="display:none"> <img src="img/icons/no-icon-available.png" class="pull-left" style="" /> <p> <strong class="font-1" style="margin-left:10px;">Hajime Sasota </strong> Sample comment<br/> <div class="btn4" style=""> <span style=""><abbr class="timeago" title="">time</abbr></span> </div> </p> <input type="text" class="form-control pull-right" placeholder="Write a reply..." /> </div> </div> 

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

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