如何显示两个回复,并将其余回复折叠在查看回复下.(我很难显示两个回复)
how to show two replies, and fold the rest of them under view replies. (I'm having hard time showing two replies)
我有一个评论系统,它目前折叠所有回复。我想显示两个回复,然后将它们全部折叠。现在我研究了这个 http://jsfiddle.net/isherwood/Frpmj/3/但我不太明白,因为我使用 for 循环进行回复。这是我的代码。
<div class="replyInfo">
{% if not comment.is_child %}
<div class="wholeReply">
{% if comment.comment_count %}
<a href='#' class='replies'>
{{comment.comment_count}}</a>
{% endif %}
<div class="got_replies">
<ul style="list-style-type: none;">
{% for child in comment.get_children %}
<li>
{{ child.get_comment }}
</li><hr>
{% endfor %}
</ul>
</div>
</div>
</div>
<script>
$('.replies').click(function(e){
e.preventDefault();
$(this).next(".got_replies").fadeToggle();
})
$(".got_replies").fadeToggle();
</script>
有人可以帮我吗?
您可以使用
slice()
函数选择类名为 reply
的前两个元素。 当然,您必须将类名reply
添加到您的 html 中。实时预览
添加了类名的 HTML:
<div class="replyInfo">
{% if not comment.is_child %}
<div class="wholeReply">
{% if comment.comment_count %}
<a href='#' class='replies'>
{{comment.comment_count}}</a>
{% endif %}
<div class="got_replies">
<ul style="list-style-type: none;">
{% for child in comment.get_children %}
<li class="reply"><!--added class to your li element-->
{{ child.get_comment }}
</li><hr>
{% endfor %}
</ul>
</div>
</div>
</div>
JavaScript:
$('.replies').click(function(e){
e.preventDefault();
$(this).next(".got_replies").find(".reply").slice(0,2).fadeToggle();
});
$(".reply").fadeToggle();
目前,您正在隐藏整个div。我没有测试它,但试试这个:
<script>
$('.replies').click(function(e){
e.preventDefault();
$(this).next(".got_replies").children("ul").children("li:nth-child(n+2)").fadeToggle();
})
</script>
相关文章:
- JQuery合并了keyup和focusout两个函数
- 如何使用 node.js 比较两个 json 数组
- 为复选框javascript指定两个值
- 用每小时的差值填充数组/列表-从下拉列表中给定两个时间值
- 单击时切换两个图像
- 我可以'我似乎不知道如何修复javascript中的两个lint.有人能帮我理解吗
- 基于两个条件退出While循环
- 如何在这里将两个值最低的数字相加
- 组合两个javascript函数
- 如何使用offer/answer交换来自两个对等连接的流
- jsf中两个字符串的颜色代码差异
- 加载两个具有相同父密钥名称的json文件
- 在Qualtrics中,介绍如何动态连接两个滑块
- 访问$.ajax()函数中的两个不同数组
- 如何在three.js上添加两个向量
- 如何在datetimepicker中使用两个验证器
- 如何在javascript中获取两个日期之间的周六和周日的日期
- 两个指令创建新的继承的和隔离的作用域-元素得到哪个
- javascript函数,它接受两个输入:一个对象和一个键,并返回对象中该键的相应值
- 如何显示两个回复,并将其余回复折叠在查看回复下.(我很难显示两个回复)