My flickr 继续更新

2007-9-7 1:43:19 AM
  “打造自己的flickr”仍然在继续,在发现只能通过set浏览相片后,为了能方便看到全部(包括不在set中的)相片,又新增了一个photos页面。通过调用API中的flickr.people.getPublicPhotos方法获得相片列表,并仿照flickr的方式做了分页。

当前页为前7页时


当前页在中间时


当前页为后7页时


  分页的脚本写得很笨,不满意,哪位有好的实现思路请告诉我。

实现JS脚本:
var page_num = document.getElementById("page_num" ).value;    //总页数
var page = <%=page%>;    //当前页码
var url = "<%=url%>"    //url
if(page==1){
    document.write('<span class="no_link">< Prev</span> ');    //当前为第一页时“上一页”为普通文件
}else{
    document.write('<a href="'+url+'page='+ (page-1) +'">< Prev</a> ')    //否则链接到当前页的上一页
}
    
if(page_num<=10){    //总页数小于10页则直接循环出所有页码
    for(var i=1;i<=page_num;i++){
        if(i==page){    //标记出当前页
            document.write('<span class="this_page">'+i+'</span> ');
        }else{
            document.write('<a href="'+url+'page='+i+'">'+i+'</a> ');
        }
    }
}else{
    if(page<=7){    //当前页为前七页之一时的页码显示方式: 1 2 3 4 5 6 7 8 9 … 29 30
        for(var i=1;i<=10;i++){
            if(i==page){
                document.write('<span class="this_page">'+i+'</span> ');
            }else{
                document.write('<a href="'+url+'page='+i+'">'+i+'</a> ');
            }
        }
        document.write('<span class="break">…</span> ');
        document.write('<a href="'+url+'page='+ (page_num-1) +'">'+ (page_num-1) +'</a> ')
        document.write('<a href="'+url+'page='+ page_num +'">'+ page_num +'</a>')
    }else{
        if(page>=(page_num-7)){    //当前页为后七页之一时的页码显示方式: 1 2 … 22 23 24 25 26 27 28 29 30
            document.write('<a href="'+url+'page=1">1</a> ')
            document.write('<a href="'+url+'page=2">2</a> ')
            document.write('<span class="break">…</span> ');
            for(var i=(page_num-10);i<=page_num;i++){
                if(i==page){
                    document.write('<span class="this_page">'+i+'</span> ');
                }else{
                    document.write('<a href="'+url+'page='+i+'">'+i+'</a> ');
                }
            }
        }else{ //当前页为中间部分时的显示方式: 1 2 … 15 16 17 18 19 20 21 … 29 30
            document.write('<a href="'+url+'page=1">1</a> ')
            document.write('<a href="'+url+'page=2">2</a> ')
            document.write('<span class="break">…</span> ');
            document.write('<a href="'+url+'page='+(page-3)+'">'+(page-3)+'</a> ');
            document.write('<a href="'+url+'page='+(page-2)+'">'+(page-2)+'</a> ');
            document.write('<a href="'+url+'page='+(page-1)+'">'+(page-1)+'</a> ');
            document.write('<span class="this_page">'+page+'</span> ');
            document.write('<a href="'+url+'page='+(page+1)+'">'+(page+1)+'</a> ');
            document.write('<a href="'+url+'page='+(page+2)+'">'+(page+2)+'</a> ');
            document.write('<a href="'+url+'page='+(page+3)+'">'+(page+3)+'</a> ');
            document.write('<span class="break">…</span> ');
            document.write('<a href="'+url+'page='+ (page_num-1) +'">'+ (page_num-1) +'</a> ')
            document.write('<a href="'+url+'page='+ page_num +'">'+ page_num +'</a>')
        }
    }
}
    
if(page==page_num){
    document.write('<span class="no_link">Next ></span>');    //当前为最末页时“下一页”显示为普通文字
}else{
    document.write(' <a href="'+url+'page='+ (page+1) +'">Next ></a>')    //否则链接到当前页的下一页
}
Comments [3] | TrackBack[0] | 2316 views | TrackBack
ato - 9/7/2007 1:14:52 PM
1
http://www.dcshooter.com/
这个站没了?
poorfish - 9/7/2007 2:45:17 PM
2
暂停中...
jy1376 - 3/22/2009 8:15:53 PM
3
good

Add your own comment

Name:       *

Password:

Code:        

Your Comment: