JS无刷新分页插件
2016-02-26 15:26
507 查看
本文介绍一个本人自己写的一JS分页插件
页面JS调用,实例化带参数的函数
参数说明
pagesize:指定每页行数
url:请求数据的接口地址
ext:class名称的后缀,本文写了1,每个class名称后面都有个1,就是这个1了,这样一个页面就可以实例多次
async:是否异步
显示class名称
当前页:smart_page_pageindex
总页数:smart_page_pagecount
每页行数:smart_page_pagesize
总行数:smart_page_rowcount
按钮class名称
首页:smart_page_first
上一页:smart_page_pre
下一页:smart_page_next
末页:smart_page_last
如果是手机加载更多的方式点下一页也是smart_page_next
放置数据的容器class名称smart_page_dataspace
接口的page.ashx文件全文
View Code
smart.page.min.zip文件下载
<script src="/Js/smart.page.min.js" type="text/javascript"></script>
页面JS调用,实例化带参数的函数
function pageplugin(pagesize, url, ext, async)
参数说明
pagesize:指定每页行数
url:请求数据的接口地址
ext:class名称的后缀,本文写了1,每个class名称后面都有个1,就是这个1了,这样一个页面就可以实例多次
async:是否异步
<script type="text/javascript"> //实例化函数,每页3行,接口为/Test/Page.ashx?a=1,class名称后缀为1 var page = new pageplugin(3, '/Test/Page.ashx?a=1',1); // page.append = true;//加载更多的方式翻页 page.dataspace = "smart_page_dataspace1";//放置展示数据的容器 page.setdata = function (data) { var json = eval('(' + data + ')'); var html = "<table>"; for (var i = 0; i < json.list.length; i++) { html += "<tr>"; html += "<td>" + json.list[i].Id + "</td><td>" + json.list[i].UserName + "</td>"; html += "</tr>"; } html += "</table>"; this.sethtml(html); //将拼接的Html打印出来 } page.getdata(); //初始化加载第一页数据 </script>
显示class名称
当前页:smart_page_pageindex
总页数:smart_page_pagecount
每页行数:smart_page_pagesize
总行数:smart_page_rowcount
<span title="当前页" class="smart_page_pageindex1"></span>/<span title="总页数" class="smart_page_pagecount1"></span>页 <span title="每页行数" class="smart_page_pagesize1"></span>条每页 总共<span title="总行数" class="smart_page_rowcount1"></span>条
按钮class名称
首页:smart_page_first
上一页:smart_page_pre
下一页:smart_page_next
末页:smart_page_last
<input class="smart_page_first1" type="button" value="首页" /> <input class="smart_page_pre1" type="button" value="上一页" /> <input class="smart_page_next1" type="button" value="下一页" /> <input class="smart_page_last1" type="button" value="末页" />
如果是手机加载更多的方式点下一页也是smart_page_next
<div class="smart_page_next1">加载更多</div>
放置数据的容器class名称smart_page_dataspace
<div class="smart_page_dataspace1"></div>
接口的page.ashx文件全文
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="/Js/smart.page.min.js" type="text/javascript"></script>
</head>
<body>
<div class="smart_page_dataspace1">
</div>
<div>
<span title="当前页" class="smart_page_pageindex1"></span>/<span title="总页数" class="smart_page_pagecount1"></span>页 <span title="每页行数" class="smart_page_pagesize1"></span>条每页 总共<span title="总行数" class="smart_page_rowcount1"></span>条
</div>
<input class="smart_page_first1" type="button" value="首页" /> <input class="smart_page_pre1" type="button" value="上一页" /> <input class="smart_page_next1" type="button" value="下一页" /> <input class="smart_page_last1" type="button" value="末页" />
<div class="smart_page_next1">
加载更多</div>
</body>
<script type="text/javascript">
//实例化函数,每页3行,接口为/Test/Page.ashx?a=1,class名称后缀为1
var page = new pageplugin(3, '/Test/Page.ashx?a=1', 1);
page.append = true; //加载更多的方式翻页
page.dataspace = "smart_page_dataspace1"; //放置展示数据的容器
page.setdata = function (data) {
var json = eval('(' + data + ')');
var html = "<table>";
for (var i = 0; i < json.list.length; i++) {
html += "<tr>";
html += "<td>" + json.list[i].Id + "</td><td>" + json.list[i].UserName + "</td>";
html += "</tr>";
}
html += "</table>";
this.sethtml(html); //将拼接的Html打印出来
}
page.getdata(); //初始化加载第一页数据
</script>
</html>
View Code
smart.page.min.zip文件下载
相关文章推荐
- MVC5序列化Json时遇到的大小写问题及解决方法
- ExtJS4中initComponent和constructor的区别
- 探究问题:ssh+extjs 权限角色用户功能的实现
- JS时间格式化
- javascript 立即执行函数的写法
- JavaScript的事件代理
- javascript 快速排序算法
- html + css + javascript 制作时间轴
- JS正则表达式重点总结
- 爬虫:selenium + phantomjs 解决js抓取问题(一)
- js系列-4 继承
- js系列-3 js作用域与闭包
- js系列-2 js函数相关
- 一款在线测试网页性能速度的工具,web开发必备
- Javascript基础恶补
- Extjs 文本框设置焦点 待整理
- js系列-1 js对象相关
- js中匿名函数的N种写法
- Javascript和CSS浏览器兼容性方面经验总结
- 原生javascript实现匀速运动动画效果