我在這裏有一個相當簡單的分頁算法,但它沒有按照我喜歡的方式工作。分頁算法工作不正確
目前它顯示這樣
1 2 3 ... 33 34 35 [36] 37 38 ... 47 48 49 50
當應顯示這樣
1 2 3 ... 33 34 35 [36] 37 38 39 ... 48 49 50
這裏是我的代碼,我很快寫的。它也似乎不斷運行(循環不停止),但我不知道爲什麼。
$(function(){
var pages = 50; //Total number of pages
var current = 36; //The current page we are on
var before = 3; //Number of links to display before current
var after = 3; //Same as above but after
var start = (current - before); //The number of the first link
var end = (current + after); //Number of the end link
for(var i = 1; i <= pages; i++){
if(i == (before + 1)){
i = start;
document.write('...');
}
else if(i == (current + after)){
i = (pages - after);
document.write('...');
}
if(i == current){
document.write(' ['+i+'] ');
}
else{
document.write(' '+i+' ');
}
}
});
+1因爲我不明白爲什麼這應該是-1。 – Mizipzor 2010-02-19 14:44:17