public static string GetPageBarStr(int pageIndex, int pageSize, int pageCount, int recordCount)
{
StringBuilder sb = new StringBuilder();
string domStrStart = "";
string domStrEnd = "";
if (pageIndex<1)
{
pageIndex = 1;
}
int start = pageIndex - 2;
if (start <= 2)
{
start = 2;
}
int end = start + 4;
if (end > pageCount)
{
end = pageCount;
start = end - 4;
if (start <= 2)
{
start = 2;
}
}
if (pageCount == 1)
{
start = 1;
}
// 1 ... 3 4 5 6 7 ... 12
if (start > 2)
{
domStrStart = "<span>...</span>";
}
if (pageCount - 1 > end)
{
domStrEnd = "<span>...</span>";
}
for (int i = start; i <= end; i++)
{
if (pageIndex != i)
{
sb.Append("<a href='javascript:void(0)' onclick='pageBarGo(" + (i) + ")'>" + i + "</a>");
}
else
{
sb.Append("<span>" + i + "</span>");
}
}
StringBuilder sb2 = new StringBuilder();
if (pageIndex == 1)
{
sb2.Append("<div class='pageBarDiv'><span>上一页</span>");
}
else
{
sb2.Append("<div class='pageBarDiv'><a href='javascript:void(0)' onclick='pageBarGo(" + (pageIndex - 1) + ")'>上一页</a>");
}
if (start != 1)
{
if (pageIndex != 1)
{
sb2.Append("<a href='javascript:void(0)' onclick='pageBarGo(1)'>" + 1 + "</a>" + domStrStart);
}
else
{
sb2.Append("<span>" + 1 + "</span>" + domStrStart);
}
}
sb2.Append(sb.ToString());
if (end != pageCount)
{
if (pageIndex != pageCount && pageCount!=0)
{
sb2.Append(domStrEnd + "<a href='javascript:void(0)' onclick='pageBarGo(" + (pageCount) + ")'>" + pageCount + "</a>");
}
else
{
sb.Append(domStrEnd + "<span>" + pageCount + "</span>");
}
}
if (pageIndex == pageCount || pageCount == 0)
{
sb2.Append("<span>下一页</span>");
}
else
{
sb2.Append("<a href='javascript:void(0)' onclick='pageBarGo(" + (pageIndex + 1) + ")'>下一页</a>");
}
sb2.Append("共<span class='redspan'>" + recordCount + "</span>条数据,每页显示<input type='text' value='" + pageSize + "' id='pageBar_pageSize'/>条 转到<input type='text' value='" + pageIndex + "' id='pageBar_skip'/><input type='button' value='确定' onclick='pageBarSkip()'/></div><style>.pageBarDiv a {color:#915833; margin-right:5px;} .pageBarDiv span{ margin-right:5px;color:#444444;} .pageBarDiv input[type='text']{width:30px;color:#444444;} .pageBarDiv .redspan{margin-right:3px; margin-left:3px;color:red;} .pageBarDiv button{text-align:center;padding-left:3px;padding-right:3px;color:white;border:none;border-radius:2px;}</style>");
return sb2.ToString();
}
<script>
function pageBarGo(pageIndex) {
ajaxGetData(pageIndex);
}
function pageBarSkip() {
ajaxGetData();
}
function ajaxGetData(pageIndex) {
var pageSize = $("#pageBar_pageSize").val();
var pageSkip = $("#pageBar_skip").val();
if (pageIndex==null) {
pageIndex = pageSkip;
}
if (checkPageBarData(pageSize, pageSkip))
{
var data = $("#f1").serialize() + "action=ajaxGetData&pageIndex=" + pageIndex + "&pageSize=" + pageSize;
alert(data);
$.ajax({
url: "/system/DictAjax",
type: "post",
data: data ,
success: function (response) {
if (response.indexOf("~fuck~")>=0) {
var da = response.split("~fuck~");
if (da[1]=="ok") {
$(".layui-table").find("tr:gt(0)").remove();
$(".layui-table").append(da[2]);
}
else {
layer.msg(da[1]);
}
}
else {
window.top.location.href = "/login/manage";
}
}
});
}
}
function checkPageBarData(pageSize, pageSkip) {
if (isNaN(pageSize) ) {
layer.msg("每页显示数量需是0-50的整数。");
return false;
}
if (isNaN(pageSkip)) {
layer.msg("跳到的页数需是正整数。");
return false;
}
var ps = parseInt(pageSize);
if ( ps<= 0 || ps>50) {
layer.msg("每页显示数量需是0-50的整数。");
return false;
}
var pk = parseInt(pageSkip);
if (pk<=0) {
layer.msg("跳到的页数需是正整数。");
return false;
}
return true;
}
</script>