28,391
社区成员
发帖
与我相关
我的任务
分享
<html>
<body>
<div id="myvicy"></div>
<script type="text/javascript">
curPage=parseInt(location.search.replace(/.*?page=(-?\d+)/,"$1"))||1; //初始选择的是第一页
viewPage=10
ctPage = 20
url = ""
function listPagebar(curPage){
var centerPage=Math.ceil(viewPage/2),spacePage = Math.floor(viewPage/2) ;
var html = "";
curPage=curPage<1?1:curPage>ctPage?ctPage:curPage;
centerPage = curPage<centerPage?centerPage:curPage>ctPage-centerPage+1?ctPage-centerPage+1:curPage;
barstr = '<span><a href="'+url+'?page=parm" style="cursor:hand;width:18px;cstr">pg</a></span> '
for(var j=(centerPage-spacePage);j<=(centerPage+spacePage);j++){
if(j<1||j>ctPage)continue
cstr=curPage==j?"color:red":"";
html += barstr.replace(/parm/,j).replace(/cstr/,cstr).replace(/pg/,j)
}
p = barstr.replace(/parm/,(curPage-1)).replace(/pg/,'<')
n = barstr.replace(/parm/,(curPage+1)).replace(/pg/,'>')
pp = barstr.replace(/parm/,(centerPage-viewPage)).replace(/pg/,'<<')
nn = barstr.replace(/parm/,(centerPage+viewPage)).replace(/pg/,'>>')
document.getElementById('myvicy').innerHTML = pp+p+ html+n+nn;
}
window.onload = function(){
listPagebar(curPage);
}
</script>
</body>
</html>
<html>
<body>
<div id="myvicy"></div>
<script type="text/javascript">
curPage=parseInt(location.search.replace(/.*?page=(-?\d+)/,"$1"));
viewPage=10
ctPage = 20
url = ""
function listPagebar(curPage){
var centerPage=Math.ceil(viewPage/2),spacePage = Math.floor(viewPage/2) ;
var html = "";
curPage=curPage<1?1:curPage>ctPage?ctPage:curPage;
centerPage = curPage<centerPage?centerPage:curPage>ctPage-centerPage+1?ctPage-centerPage+1:curPage;
barstr = '<span><a href="'+url+'?page=parm" style="cursor:hand;width:18px;cstr">pg</a></span> '
for(var j=(centerPage-spacePage);j<=(centerPage+spacePage);j++){
if(j<1||j>ctPage)continue
cstr=curPage==j?"color:red":"";
html += barstr.replace(/parm/,j).replace(/cstr/,cstr).replace(/pg/,j)
}
p = barstr.replace(/parm/,(curPage-1)).replace(/pg/,'<')
n = barstr.replace(/parm/,(curPage+1)).replace(/pg/,'>')
pp = barstr.replace(/parm/,(centerPage-viewPage)).replace(/pg/,'<<')
nn = barstr.replace(/parm/,(centerPage+viewPage)).replace(/pg/,'>>')
document.getElementById('myvicy').innerHTML = pp+p+ html+n+nn;
}
window.onload = function(){
listPagebar(curPage); //初始选择的是第一页
}
</script>
</body>
</html>
<html>
<body>
<div id="div1">
</div>
<script type="text/javascript">
function FormatDiv(curPage)
{
var html = "";
if(curPage<5) //如果点击的页数小于5,就实现 1 2 3 4 5
{
for(var i=1;i<=5;i++)
{
html += '<span onclick=FormatDiv('+i+')>'+i+"</span>";
}
}
else //如果点击的页数大于5,就显示 curPage-2 curPage-1 curPage curPage+1 curPage+2
{
for(var j=(curPage-2);j<=(curPage+2);j++)
{
html += '<span onclick=FormatDiv('+j+')>'+j+"</span>";
}
}
document.getElementById('div1').innerHTML = html;
}
window.onload = function(){
FormatDiv(1); //初始选择的是第一页
}
</script>
</body>
</html>