求js分页,调用方法 页面样式 <div><ul><li></li></ul><ul><li></li></ul><ul><li></li></ul></div>
2个回答
展开全部
<div id="page">
<ul><li>第111111页的内容</li></ul>
<ul><li>第222222页的内容</li></ul>
<ul><li>第333333页的内容</li></ul>
</div>
<div id="innerpage"></div>
<script type="text/javascript">
//Page
var obj,j;
var page=0;
var nowPage=0; //当前页
var listNum=1; //每页显示条数
var PagesLen; //总页数
var PageNum=10; //分页链接数(5个)
onload=function(){
obj=document.getElementById("page").getElementsByTagName("ul");
j=obj.length
PagesLen=Math.ceil(j/listNum);
upPage(0)
}
function upPage(p){
nowPage=p
//内容变换
for (var i=0;i<j;i++){
obj[i].style.display="none"
}
for (var i=p*listNum;i<(p+1)*listNum;i++){
if(obj[i])obj[i].style.display="block"
}
strS='<a href="JavaScript:FirstPage()" onclick="upPage(0)">首页</a> '
var PageNum_2=PageNum%2==0?Math.ceil(PageNum/2)+1:Math.ceil(PageNum/2)
var PageNum_3=PageNum%2==0?Math.ceil(PageNum/2):Math.ceil(PageNum/2)+1
var strC="",startPage,endPage;
if (PageNum>=PagesLen) {startPage=0;endPage=PagesLen-1}
else if (nowPage<PageNum_2){startPage=0;endPage=PagesLen-1>PageNum?PageNum:PagesLen-1}//首页
else {startPage=nowPage+PageNum_3>=PagesLen?PagesLen-PageNum-1: nowPage-PageNum_2+1;var t=startPage+PageNum;endPage=t>PagesLen?PagesLen-1:t}
for (var i=startPage;i<=endPage;i++){
if (i==nowPage)strC+='<a href="JavaScript:curPage()" class="curpage" onclick="upPage('+i+')">'+(i+1)+'</a> '
else strC+='<a href="#JavaScript:Page()" onclick="upPage('+i+')">'+(i+1)+'</a> '
}
strE=' <a href="JavaScript:LastPage()" onclick="upPage('+(PagesLen-1)+')">尾页</a> '
strE2=nowPage+1+"/"+PagesLen+"页"+" 共"+j+"条"
document.getElementById("innerpage").innerHTML=strS+strC+strE+strE2
}
</script>
<ul><li>第111111页的内容</li></ul>
<ul><li>第222222页的内容</li></ul>
<ul><li>第333333页的内容</li></ul>
</div>
<div id="innerpage"></div>
<script type="text/javascript">
//Page
var obj,j;
var page=0;
var nowPage=0; //当前页
var listNum=1; //每页显示条数
var PagesLen; //总页数
var PageNum=10; //分页链接数(5个)
onload=function(){
obj=document.getElementById("page").getElementsByTagName("ul");
j=obj.length
PagesLen=Math.ceil(j/listNum);
upPage(0)
}
function upPage(p){
nowPage=p
//内容变换
for (var i=0;i<j;i++){
obj[i].style.display="none"
}
for (var i=p*listNum;i<(p+1)*listNum;i++){
if(obj[i])obj[i].style.display="block"
}
strS='<a href="JavaScript:FirstPage()" onclick="upPage(0)">首页</a> '
var PageNum_2=PageNum%2==0?Math.ceil(PageNum/2)+1:Math.ceil(PageNum/2)
var PageNum_3=PageNum%2==0?Math.ceil(PageNum/2):Math.ceil(PageNum/2)+1
var strC="",startPage,endPage;
if (PageNum>=PagesLen) {startPage=0;endPage=PagesLen-1}
else if (nowPage<PageNum_2){startPage=0;endPage=PagesLen-1>PageNum?PageNum:PagesLen-1}//首页
else {startPage=nowPage+PageNum_3>=PagesLen?PagesLen-PageNum-1: nowPage-PageNum_2+1;var t=startPage+PageNum;endPage=t>PagesLen?PagesLen-1:t}
for (var i=startPage;i<=endPage;i++){
if (i==nowPage)strC+='<a href="JavaScript:curPage()" class="curpage" onclick="upPage('+i+')">'+(i+1)+'</a> '
else strC+='<a href="#JavaScript:Page()" onclick="upPage('+i+')">'+(i+1)+'</a> '
}
strE=' <a href="JavaScript:LastPage()" onclick="upPage('+(PagesLen-1)+')">尾页</a> '
strE2=nowPage+1+"/"+PagesLen+"页"+" 共"+j+"条"
document.getElementById("innerpage").innerHTML=strS+strC+strE+strE2
}
</script>
追问
谢谢您的回答,很有帮助,但是 JavaScript:curPage()JavaScript:Page()JavaScript:LastPage()未定义,运行时会有误,去掉后页面会出现刷新效果,怎么解决呢
追答
href中的javascript....完全可以去掉,不影响。
去与不去,我运行都不报错啊
展开全部
<div id="page">
<ul><li>第1页的内容</li></ul>
<ul><li>第2页的内容</li></ul>
<ul><li>第3页的内容</li></ul>
</div>
<div id="innerpage"></div>
<script type="text/javascript">
//Page
var obj,j;
var page=0;
var nowPage=0; //当前页
var listNum=1; //每页显示的条数
var PagesLen; //总的页数
var PageNum=10; //分页链接数(5个)
onload=function(){
obj=document.getElementById("page").getElementsByTagName("ul");
j=obj.length
PagesLen=Math.ceil(j/listNum);
upPage(0)
}
function upPage(p){
nowPage=p
//内容的变换
for (var i=0;i<j;i++){
obj[i].style.display="none"
}
for (var i=p*listNum;i<(p+1)*listNum;i++){
if(obj[i])obj[i].style.display="block"
}
strS='<a href="JavaScript:FirstPage()" onclick="upPage(0)">首页</a> '
var PageNum_2=PageNum%2==0?Math.ceil(PageNum/2)+1:Math.ceil(PageNum/2)
var PageNum_3=PageNum%2==0?Math.ceil(PageNum/2):Math.ceil(PageNum/2)+1
var strC="",startPage,endPage;
if (PageNum>=PagesLen) {startPage=0;endPage=PagesLen-1}
else if (nowPage<PageNum_2){startPage=0;endPage=PagesLen-1>PageNum?PageNum:PagesLen-1}//首页
else {startPage=nowPage+PageNum_3>=PagesLen?PagesLen-PageNum-1: nowPage-PageNum_2+1;var t=startPage+PageNum;endPage=t>PagesLen?PagesLen-1:t}
for (var i=startPage;i<=endPage;i++){
if (i==nowPage)strC+='<a href="JavaScript:curPage()" class="curpage" onclick="upPage('+i+')">'+(i+1)+'</a> '
else strC+='<a href="#JavaScript:Page()" onclick="upPage('+i+')">'+(i+1)+'</a> '
}
strE=' <a href="JavaScript:LastPage()" onclick="upPage('+(PagesLen-1)+')">尾页</a> '
strE2=nowPage+1+"/"+PagesLen+"页"+" 共"+j+"条"
document.getElementById("innerpage").innerHTML=strS+strC+strE+strE2
}
</script>
<ul><li>第1页的内容</li></ul>
<ul><li>第2页的内容</li></ul>
<ul><li>第3页的内容</li></ul>
</div>
<div id="innerpage"></div>
<script type="text/javascript">
//Page
var obj,j;
var page=0;
var nowPage=0; //当前页
var listNum=1; //每页显示的条数
var PagesLen; //总的页数
var PageNum=10; //分页链接数(5个)
onload=function(){
obj=document.getElementById("page").getElementsByTagName("ul");
j=obj.length
PagesLen=Math.ceil(j/listNum);
upPage(0)
}
function upPage(p){
nowPage=p
//内容的变换
for (var i=0;i<j;i++){
obj[i].style.display="none"
}
for (var i=p*listNum;i<(p+1)*listNum;i++){
if(obj[i])obj[i].style.display="block"
}
strS='<a href="JavaScript:FirstPage()" onclick="upPage(0)">首页</a> '
var PageNum_2=PageNum%2==0?Math.ceil(PageNum/2)+1:Math.ceil(PageNum/2)
var PageNum_3=PageNum%2==0?Math.ceil(PageNum/2):Math.ceil(PageNum/2)+1
var strC="",startPage,endPage;
if (PageNum>=PagesLen) {startPage=0;endPage=PagesLen-1}
else if (nowPage<PageNum_2){startPage=0;endPage=PagesLen-1>PageNum?PageNum:PagesLen-1}//首页
else {startPage=nowPage+PageNum_3>=PagesLen?PagesLen-PageNum-1: nowPage-PageNum_2+1;var t=startPage+PageNum;endPage=t>PagesLen?PagesLen-1:t}
for (var i=startPage;i<=endPage;i++){
if (i==nowPage)strC+='<a href="JavaScript:curPage()" class="curpage" onclick="upPage('+i+')">'+(i+1)+'</a> '
else strC+='<a href="#JavaScript:Page()" onclick="upPage('+i+')">'+(i+1)+'</a> '
}
strE=' <a href="JavaScript:LastPage()" onclick="upPage('+(PagesLen-1)+')">尾页</a> '
strE2=nowPage+1+"/"+PagesLen+"页"+" 共"+j+"条"
document.getElementById("innerpage").innerHTML=strS+strC+strE+strE2
}
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询