javascript - 如何在 django 中激活显示更多按钮并每页显示 3 个项目
问题描述
我正在尝试每页显示 3 个项目,如果用户按下show more
按钮,它将加载更多 3 个项目
视图.py:
def home_page(request):
pcgamesforhome = PCgames.objects.all()
context = {'pcgamesforhome' : pcgamesforhome}
return render(request,'html_file/enterface.html',context=context)
html页面:
<div class="container">
<div class='row'>
{% for home_page in pcgamesforhome %}
<div class='col-xs-12 col-sm-6 col-md-4 website-thumb'>
<a href="{{ home_page.page_url }}">
<img src="{{ home_page.get_image }}" class='image_control_for_home_page_pc_games' alt=''> </a>
<h3 class="font_control_for_home_page_pc_games_name"><a href="{{ home_page.page_url }}" style="color:black">{{ home_page.name }}</a></h3> </div>
{% endfor %}
</div>
<div class="text-center mt-4">
<a role="presentation" type="button" class="btn btn-secondary btn-lg loadMore" style="width:40%">Show More</a>
</div>
<script>
$(".row").slice(0, 3).show(); //showing 3 div
$(".loadMore").on("click",function(){
$(".row:hidden").slice(0, 3).show(); //showing 3 hidden div on click
if($(".row:hidden").length ==0)
{
$(".loadMore").fadeOut(); //this will hide
//button when length is 0
}
})
</script>
那么我的代码有什么问题,(我的 html 页面现在一次显示模型中的所有项目而不是 3)
解决方案
推荐阅读
- javascript - 切换按钮的背景颜色不起作用
- php - 我应该在哪里添加我的 add_action(init 以便我可以使用 wp_set_object_terms?
- kivy - minimum_height 在 .py 内的布局中不起作用(仅在 .kv 中起作用)?
- node.js - 安装 zsh 和 yvm 后终端完全崩溃并卡住(无法输入,Ctrl C 不起作用)
- javascript - 如何独立于特定的相机轴移动相机?
- java - 如何在不创建新对象的情况下测试私有成员对象
- vue.js - 如何在 Vue.js 中动态延迟加载 SCSS 文件?
- amazon-ses - Nodemailer SES TRANSPORT 错误:“UnexpectedParameter:在参数中找到意外的键 'Destination'”
- vue.js - Vue.js 在构建生产时配置根目录
- jasper-reports - Jasper Report Chart 操作 labelExpression