//分页异步加载方法 layui.use(['laypage','element'], function(){ var laypage = layui.laypage,$ = layui.jquery,element = layui.element; //点击热门分类 $('#type li').click(function () { var typename=$(this).text(); f(1,typename); }) //点击文档格式 $('#format li').click(function () { var format=$(this).text(); f(1,'',format); }) //点击时间范围 $('#timetype li').click(function () { var timetype=$(this).text(); f(1,'','',timetype); }) //点击付费模式 $('#jiage li').click(function () { var price=$(this).text(); f(1,'','','',price); }) //点击价格范围 $('.xuanze_btn').click(function() { var price=$("[name='interest'] option:selected").val(); $('#jiage li').removeClass('layui-this'); f(1,'','','',price); }) //分页 //首页加载 pageinit(1, $('#count').text()); function pageinit(curr, count) { laypage.render({ elem: 'demo3' , count: count , layout: ['count', 'prev', 'page', 'next'] , first: '首页' , last: '尾页' , limit: $('#limit').text() , prev: '←' , next: '→' , curr: curr , jump: function (obj, first) { //obj包含了当前分页的所有参数,比如: console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。 console.log(obj.limit); //得到每页显示的条数 //首次不执行 if (!first) { //请求数据 f(obj.curr) } } }); } //封装异步请求数据 function f(page,type='',format='',timetype='',price=''){ loading =layer.load(1, {shade: [0.1,'#fff']}); if(type==''){ type=$("#type .layui-this").text(); } if(format==''){ format=$("#format .layui-this").text(); } if(timetype==''){ timetype=$("#timetype .layui-this").text(); } price=$("[name='interest'] option:selected").val(); if(!price){ price=$("#jiage .layui-this").text(); } type = type=='全部'?'':type; format = format=='全部'?'':format; timetype = timetype=='综合'?'':timetype; $.ajax({ url:$('#url').text(), data: { "typeid": $('#typeid').text(), "keys": $('#keys').text(), "page": page, "type":type, "price":price, "format":format, "timetype":timetype, }, type: "POST", async:true, success:function(data){ if(data.code==0){ var list=data.data; layer.close(loading); var sb=''; list.forEach(element => { sb+='
  • '; sb+=''+element['title']+''; sb+=''; sb+=''+element['title']+''; sb+='

    '+element['download']+'下载

    '+element['pages']+'页

  • '; }); $('#alllist').html(sb); console.log(data.count); pageinit(page, data.count) } } }); } });