![]()
<div id="PageNum">
<div class="txtAll">
<span class="totalPage" id="txtAll"></span>
</div>
<div class="fenye">
<input type="button" id="btnPrev" value="前十页" />
<ul>
</ul>
<input type="button" id="btnNext" value="后十页" />
到<input type="text" id="txtIndex" />页<input type="button" id="btnConfirm" value="确定" />
</div>
</div>
//滚动定位到product
function scroll() {
var scroll_offset = $("#product").offset();
$("body,html").animate({
scrollTop: scroll_offset.top
}, 0);
}
//分页
function getPageNum(AllCount) {
$("#PageNum ul").empty();
var total = Math.ceil(AllCount / 5); //数据可分的页数
var totalCount = Math.ceil(total / 10);
var allhtml = "共<strong style='margin: auto 3px;'>" + total + "</strong>页";
$("#txtAll").html(allhtml);
for (var i = 1; i < total + 1; i++) {
var html = "<li><a>" + i + "</a></li>";
$("#PageNum ul").append(html);
}
$("#PageNum ul li").eq(0).addClass("PageNumcurrent")
var current = 1;
$("#PageNum ul li:gt(9)").hide();
$("#btnPrev").click(function () {
$("#btnNext").removeAttr("disabled");
current -= 1;
if (current <= 0)
current = 1;
$("#PageNum ul li").hide();
var indexStart = (current - 1) * 10;
var indexEnd = indexStart + 10;
$(" #PageNum ul li").hide().slice(indexStart, indexEnd).show();
});
$("#btnNext").click(function () {
$("#btnPrev").removeAttr("disabled");
current += 1;
if (current > totalCount)
current = totalCount;
$("#PageNum ul li").hide();
var indexStart = (current - 1) * 10;
var indexEnd = current * 10 - 1 > $("#PageNum ul li").length - 1 ? $("#PageNum ul li").length - 1 : current * 10 - 1;
$(" #PageNum ul li").hide().slice(indexStart, indexEnd + 1).show();
});
$("#PageNum ul li").click(function () { //点击数字
$("#txtIndex").val("");
$("#PageNum ul li").removeClass();
$(this).addClass("PageNumcurrent");
var index = $(this).index();
getPageCurrent(index);
})
$("#btnConfirm").click(function () {//搜索页
var index = $("#txtIndex").val();
if (index > total || index == "" || index < 1) {
$("#txtIndex").val("");
return;
}
if (!IsNum(index)) {
$("#txtIndex").val("");
return;
}
if (index % 10 == 0) {
var indexStart = (Math.ceil(index / 10) - 1) * 10;
}
else {
indexStart = index - (index % 10);
}
var indexEnd = indexStart + 10;
$(" #PageNum ul li").hide().slice(indexStart, indexEnd).show();
$("#PageNum ul li").removeClass();
$(" #PageNum ul li").eq(index - 1).addClass("PageNumcurrent");
getPageCurrent(index - 1);
$("#txtIndex").val("");
})
}
function getPageCurrent(index) {
var indexStart = index * 5;
var indexEnd = indexStart + 5;
$(" #thumbWrap_controlID ul li").hide().slice(indexStart, indexEnd).show();
}