简单的js分页 免刷新 免跳转页面(即免&page=2页面跳转)
2016-11-28 14:12
246 查看
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Comment.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="Scripts/jquery.min.js"></script>
<script type="text/javascript">
//初始化
$(function () {
getList(1);//默认第1页
});
//清空
function ClearTable() {
$("#myTb").empty();
var tbBody = "<tr><th>编号</th><th>评论</th><th>日期</th></tr>";
$("#myTb").append(tbBody);
}
//查询数据(参数:页码)
function getList(p) {
ClearTable();
var size = 5;//每页几行数据
var index = p;//页码
$.ajax({
type: "Post",
url: "index.aspx/GetComment",
data: "{'pageSize':" + size + ",'pageIndex':" + index + "}",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
json = $.parseJSON(data.d);
for (var i in json) {
var tbBody = "";
tbBody += "<tr align='center'>";
tbBody += "<td>" + json[i].ComID + "楼</td>";
tbBody += "<td>";
tbBody += json[i].ComText;
if (json[i].ComPIC != "" && json[i].ComPIC != null) {
tbBody += "<br /><img width='50px' src='upload/" + json[i].ComPIC + "' />";
}
tbBody += "</td>";
tbBody += "<td>" + json[i].ComDate + "</td>";
tbBody += "</tr>";
$("#myTb").append(tbBody);
}
Pages(p); //分页按钮
},
error: function (err) { }
});
}
//分页按钮
function Pages(p) {
$("#pager").html("");
var size = 5;//每页几行数据
var index = p;//页码
$.ajax({
type: "Post",
url: "index.aspx/GetCommentCount",
data: "{'name':'" + name + "'}",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
var count = data.d;
if (count != null && count != 0) {
var pagecount = parseInt(count / size);//求总页数
var temp = count % size;//判断判断最后一页
if (temp > 0) {
pagecount = pagecount + 1;
}
var page = "";
for (var i = 0; i < pagecount; i++) {
if ((i + 1) == index) {
page += "<a style='color:red;'>[" + (i + 1) + "]</a> ";
}
else {
page += "<a style='color:blue;' onclick='getList(" + (i + 1) + ")'>[" + (i + 1) + "]</a> ";
}
}
$("#pager").append(page);
}
},
error: function (err) { }
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<%--<h3>评论</h3>--%>
<table id="myTb" style="width: 350px; border: solid 1px; font-size: small;" border="1" cellspacing="0" cellpadding="0"></table>
<span id="pager"></span>
<br />
<a href="#" onclick="getList(1)">刷新</a> | <a href="Comment.aspx" target="_top">我要评论</a>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Comment.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="Scripts/jquery.min.js"></script>
<script type="text/javascript">
//初始化
$(function () {
getList(1);//默认第1页
});
//清空
function ClearTable() {
$("#myTb").empty();
var tbBody = "<tr><th>编号</th><th>评论</th><th>日期</th></tr>";
$("#myTb").append(tbBody);
}
//查询数据(参数:页码)
function getList(p) {
ClearTable();
var size = 5;//每页几行数据
var index = p;//页码
$.ajax({
type: "Post",
url: "index.aspx/GetComment",
data: "{'pageSize':" + size + ",'pageIndex':" + index + "}",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
json = $.parseJSON(data.d);
for (var i in json) {
var tbBody = "";
tbBody += "<tr align='center'>";
tbBody += "<td>" + json[i].ComID + "楼</td>";
tbBody += "<td>";
tbBody += json[i].ComText;
if (json[i].ComPIC != "" && json[i].ComPIC != null) {
tbBody += "<br /><img width='50px' src='upload/" + json[i].ComPIC + "' />";
}
tbBody += "</td>";
tbBody += "<td>" + json[i].ComDate + "</td>";
tbBody += "</tr>";
$("#myTb").append(tbBody);
}
Pages(p); //分页按钮
},
error: function (err) { }
});
}
//分页按钮
function Pages(p) {
$("#pager").html("");
var size = 5;//每页几行数据
var index = p;//页码
$.ajax({
type: "Post",
url: "index.aspx/GetCommentCount",
data: "{'name':'" + name + "'}",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
var count = data.d;
if (count != null && count != 0) {
var pagecount = parseInt(count / size);//求总页数
var temp = count % size;//判断判断最后一页
if (temp > 0) {
pagecount = pagecount + 1;
}
var page = "";
for (var i = 0; i < pagecount; i++) {
if ((i + 1) == index) {
page += "<a style='color:red;'>[" + (i + 1) + "]</a> ";
}
else {
page += "<a style='color:blue;' onclick='getList(" + (i + 1) + ")'>[" + (i + 1) + "]</a> ";
}
}
$("#pager").append(page);
}
},
error: function (err) { }
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<%--<h3>评论</h3>--%>
<table id="myTb" style="width: 350px; border: solid 1px; font-size: small;" border="1" cellspacing="0" cellpadding="0"></table>
<span id="pager"></span>
<br />
<a href="#" onclick="getList(1)">刷新</a> | <a href="Comment.aspx" target="_top">我要评论</a>
</div>
</form>
</body>
</html>
相关文章推荐
- 最简单的页面自动刷新&跳转
- js实现页面定时跳转刷新【javascript】
- js中页面刷新和页面跳转的方法总结
- 2012.12.06 jquery刷新页面 页面跳转 js常用函数
- js禁止页面刷新&后退
- 转载 JS刷新页面或跳转方法(定时)
- js中页面刷新和页面跳转的方法总结
- JS定时刷新页面及跳转页面
- 困扰我的一个简单的php调用js跳转页面
- jquery刷新页面 页面跳转 js常用函数
- JS+Ajax+Jquery实现页面无刷新分页以及分组 超强的实现第1/2页
- 关于图片按钮执行js跳转页面时刷新页面的解决方案
- js页面跳转和js对iframe进行页面跳转、刷新
- 使用js刷新页面和跳转页面的几个办法总结
- JavaScript/js自动刷新页面方法总结和页面跳转
- js 刷新页面和跳转页面的几个办法本文来自: 陈华IT笔记!本文详细地址:http://www.chhua.com/it/
- JS刷新框架中的其他页面&&JS刷新窗口方法汇总
- jquery刷新页面 页面跳转 js常用函数
- jquery刷新页面 页面跳转 js常用函数
- VS 中C#下"的页面布局"简单设置のの"PageLayout属性"哪里去了