我的网页有多个问题,每个问题有多个评论。在页面加载时,我想显示每个问题的三个最新评论,并隐藏其余部分。每个问题都有一个显示/隐藏所有旧评论的链接。显示/隐藏每个部分的最新3条评论
问题是,当显示问题1的所有评论时,我点击显示问题2的所有内容,对问题1的所有旧评论都隐藏了。我希望每个显示/隐藏按钮仅影响该问题的评论。
<style type="text/css">
.user-comment-box { display:none }
</style>
<div class="comment-box-container">
<div class="comment-box"> <a class="see-more">Show all comments</a>
<div class="user-comment-box"> 0 </div>
<div class="user-comment-box"> 1 </div>
<div class="user-comment-box"> 2 </div>
<div class="user-comment-box"> 3 </div>
<div class="user-comment-box"> 4 </div>
<div class="user-comment-box"> 5 </div>
<div class="user-comment-box"> 6 </div>
</div>
</div><br />
<div class="comment-box-container">
<div class="comment-box"> <a class="see-more">Show all comments</a>
<div class="user-comment-box"> 0 </div>
<div class="user-comment-box"> 1 </div>
<div class="user-comment-box"> 2 </div>
<div class="user-comment-box"> 3 </div>
<div class="user-comment-box"> 4 </div>
<div class="user-comment-box"> 5 </div>
<div class="user-comment-box"> 6 </div>
</div>
</div>
$(function() {
// Always show last 3 comments:
$(".comment-box").each(function(index) {
$(this).children(".user-comment-box").slice(-3).show();
});
$(".see-more").click(function(e) { // click event for load more
e.preventDefault();
var link = $(this);
$(this).siblings(".user-comment-box:hidden").show(1, function() {
if ($(this).is(':visible')) {
link.text('Show less comments');
$(this).addClass('showing-more')
}
});
if ($('div').hasClass('showing-more')) {
link.text('Show all comments');
$('.showing-more').hide(1);
$('div').removeClass("showing-more");
}
});
});
小提琴:http://jsfiddle.net/5cc7qvk6/22/
不明白这个问题,现在每个展示如果你点击‘显示所有评论’的所有评论按钮仅适用于每个组 –
对于第1组,然后点击第2组的“显示所有评论”,所有关于问题1的旧评论都隐藏了(它们不应该是)。 我希望每个显示/隐藏链接仅影响该问题的评论。 – Carl