前言:
之前一直把渲染分页和请求 数据,搞在一起了,区别开以后更容易识别,数据请求方式是同步
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<link rel="stylesheet" type="text/css" href="css/layui.css"/>
</head>
<body>
<!--输入"变更",搜索后成功重置了分页-->
<input type="text" class="inp" /><span class="serch">搜索</span>
<div id="demo0"></div>
<script src="jquery.min.js"></script>
<script src="layui.all.js"></script>
<script>
var parms={
currentPage: 1,
btntype: "",
fileid: "",
id: "",
// name: "变更"
pageSize: 5,
type: "",
userid: null
}
init();
function init(){
loadData()
getPage()
}
function loadData(){
$.ajax({
type: "post",
url: "http://data.cngy.gov.cn/open/dataPool/dataPoolPager/sdh",
contentType: "application/json",
async: false,
dataType:"json",
data: JSON.stringify(parms),
success: function(data) {
console.log(data);
if(data.code==0){
parms.currentPage = data.data.currentPage;
parms.pageSize = data.data.pageSize;
parms.total = data.data.total;
}
}
});
}
function getPage(){
layui.use(['laypage', 'layer'], function(){
var laypage = layui.laypage,
layer = layui.layer;
laypage.render({
elem: 'demo0',
count:parms.total,
limit:parms.pageSize,
theme: '#D40000',
jump:function(obj,first){
if(!first){
parms.currentPage = obj.curr;
loadData()
}
}
});
})
}
$("body").on("click",".serch",function(){
var name = $('.inp').val();
parms.name = name
init();
})
</script>
</body>
</html>
搜索内容后。。。。。。。。。。。。。。。。
追加:
,prev: "<i class='iconfont icon-left'></i>"
,next: "<i class='iconfont icon-right'></i>"
if(sd.length==0){
_this.$newslistbox.html("<div style='text-align: center; margin: 20px;'><img src='/dsfa/res/dsf_styles/themes/img/nodata.png'></div>");
$('.pagebox').hide()
return false;
}