JS无刷新分页插件
本文介绍一个本人自己写的一JS分页插件
<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文件全文
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization; namespace TestWeb.Test
{
/// <summary>
/// page 的摘要说明
/// </summary>
public class page : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
int pagesize = ;
int pageindex = ;
if (!string.IsNullOrEmpty(context.Request["pagesize"]))
pagesize = Convert.ToInt32(context.Request["pagesize"]);
if (!string.IsNullOrEmpty(context.Request["pageindex"]))
pageindex = Convert.ToInt32(context.Request["pageindex"]); int rowcount = ;//替换成方法获取符合条件的行数
int pagecount = rowcount % pagesize == ? rowcount / pagesize : rowcount / pagesize + ; List<Users> list = new List<Users>();
Users u; //替换成获取指定页码的数据
for (int i = ; i <= pagesize; i++)
{
u = new Users();
u.Id = i + (pageindex - ) * pagesize;
u.UserName = this.GetType().Name + u.Id;
list.Add(u);
} string result = ObjectToJSON(new
{
@list = list,
@time1 = DateTime.Now.ToString(),
@time2 = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff"),
@pagesize = pagesize,
@pageindex = pageindex,
@rowcount = rowcount,
@pagecount = pagecount
}); context.Response.Write(result);
} /// <summary>
/// 对象转JSON
/// </summary>
/// <param name="obj">对象</param>
/// <returns>JSON格式的字符串</returns>
public static string ObjectToJSON(object obj)
{
JavaScriptSerializer jss = new JavaScriptSerializer();
try
{
return jss.Serialize(obj);
}
catch (Exception ex)
{ throw new Exception("JSONHelper.ObjectToJSON(): " + ex.Message);
}
} public bool IsReusable
{
get
{
return false;
}
}
} public class Users
{
public int Id { get; set; }
public string UserName { get; set; }
}
}
HTML页面
<!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>
JS无刷新分页插件的更多相关文章
- Asp +Js 无刷新分页
Default.aspx代码 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind=" ...
- js 无刷新分页代码
/** * 分页事件处理 */function paging(){ $("#firstPage").click(function(){ //首页 var pageNo = getP ...
- 无刷新分页 jquery.pagination.js
无刷新分页 jquery.pagination.js 采用Jquery无刷新分页插件jquery.pagination.js实现无刷新分页效果 1.插件参数列表 http://www.dtan.so ...
- Bootstrap Paginator分页插件+ajax 实现动态无刷新分页
之前做分页想过做淘宝的那个,但是因为是后台要求不高,就Bootstrap Paginator插件感觉还蛮容易上手,所以就选了它. Bootstrap Paginator分页插件下载地址: Downlo ...
- 扩展GridView实现的一个自定义无刷新分页,排序,支持多种数据源的控件TwfGridView
最近项目View层越来越趋向于无刷新化,特别是数据展示方面,还要对Linq有很好的支持.在WebFrom模式的开发中,GridView是一个功能很强大,很常用的控件,但是他也不是完美的,没有自带的无刷 ...
- 在Thinkphp中使用AJAX实现无刷新分页
在Thinkphp目录的Lib\ORG\Util\目录里新建AjaxPage.class.php,写入一下内容: <?php // +------------------------------ ...
- MVC无刷新分页(即局部刷新,带搜索,页数选择,排序功能)
我查看了很多网站,大部分评论分页都是局部刷新的,可大部分电商商品展示分页都是有刷新页面的,于是我便做了一个商品展示无刷新分页的例子.接下来我就将做一个模仿淘宝已买到的宝贝功能,不过我的是无刷新分页的. ...
- thinkphp ajax 无刷新分页效果的实现
思路:先做出传统分页效果,然后重新复制一份Page.class.php类,对它进行修改,把js中的函数传到page类中,把上一页.下一页.首页.尾页.链接页中的url地址改成js控制的函数,模板页面中 ...
- ASP.NET Ajax简单的无刷新分页
最近练习了一些AJAX无刷新分页,写得比较简单,性能不知道怎么样,求大神指点,如有更好的分页提供,欢迎交流! 发话不多说了,直接上代码! 首先从网上下了一个JS分页,感觉挺好用的 (function( ...
随机推荐
- 虚拟机virtualBox设置共享文件后,linux配置
1.在/mnt下创建共享目录 mkdir /mnt/share 2.关联外部目录 mount -t vboxsf 共享文件夹名 /mnt/share/ 如:mount -t vboxsf BaiduS ...
- AJAX - onreadystatechange
[AJAX - onreadystatechange] 参考:http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_onreadystatechang ...
- 使用新浪云 Java 环境搭建一个简单的微信处理后台
前一段时间,写了一篇在新浪云上搭建自己的网站的教程,通过简单构建了一个 maven 的项目,展示部署的整个流程,具体的操作可以参看这里. 新浪云服务器除了可以搭建自己的网站以外,也非常的适合作为微信公 ...
- Redis 缓存 + Spring 的集成示例
参考网址:http://blog.csdn.net/defonds/article/details/48716161
- Python全栈之路目录结构
基础 1.Python全栈之路-----基础篇 2.Python全栈之路---运算符与基本的数据结构 3.Python全栈之路3--set集合--三元运算--深浅拷贝--初识函数 4.Python全栈 ...
- SQL Server Management Studio 2012 设置脚本默认保存路径
特别说明,本文是从这里 修改SQL Server Management Studio默认设置提高开发效率. "抄过来的",为方便个人记忆才写此文(非常感谢这哥们儿的分享.) 原文地 ...
- asp.net Word Document Open return null
- 使用AS编译jni文件无法编译出arm64-v8a,x86_64和mips64平台的.so文件的解决方法
我用的插件版本是:classpath 'com.android.tools.build:gradle-experimental:0.4.0',AS集成和使用ndk编译项目参考官方demo:https: ...
- Python.Module.site
site " This module is automatically imported during initialization. The automatic import can be ...
- PHP标准注释
"php是一门及其容易入门的语言,刚入门的新手不到几分钟的时间可能就会用echo打印出一个hello world !但是他是真正的程序员吗?怎么来定义程序员呢?如果想真正成为一个程序员,那么 ...