日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

html如何让条数按序号输出,JS 怎么控制页面序号较智能的生成?

發(fā)布時間:2024/10/8 javascript 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html如何让条数按序号输出,JS 怎么控制页面序号较智能的生成? 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

以下為更新答案:

針對這個問題,我今天抽時間封裝了一個工具:暫且稱其為分頁驅(qū)動吧,隨便寫寫也有200行代碼。

分頁主要面臨的問題,除了顯示之后,還要考慮當前頁的獲取、當前url的參數(shù)不能丟失等等

可以看看我封裝的效果,同時提供了諸多的配置選項。主要的思想來自thinkphp5的分頁驅(qū)動

以下為原答案:

控制分頁很多時候需要考慮很多情況,根據(jù)你想要的,我只是簡單了寫個demo,這個demo能夠完整一些工作,但是本身會存在一些問題,關(guān)鍵就是判斷如何顯示,間隔多大。

Document

.pagination {

display: inline-block;

color: #337ab7;

text-decoration: none;

background-color: #fff;

border: 1px solid #ddd;

position: relative;

padding: 6px 12px;

cursor: pointer;

}

.pagination>a {

text-decoration: none;

color: darkcyan

}

APPcache

var pageIndex = {

total: 1,

now: 1,

space: 1,

min: 5,

url: 'http://url.com?page=',

urlList: [],

init: function (param) {

this.total = param.total || this.total;

this.now = param.now || this.now;

this.space = param.space || this.space;

this.min = param.min || this.min;

this.url = param.url || this.url;

return this.work();

},

work: function () {

var resArr = [];

if (this.total <= this.min) {

for (var i = 1; i <= this.total; i++) {

this.urlList.push(this.getHtml(this.url + '' + i, i, true));

}

} else {

for (var i = 1; i <= 1 + this.space; i++) {

this.urlList.push(this.getHtml(this.url + '' + i, i, true));

}

var dec = this.now - this.space;

if (dec > 1 + this.space) {

this.urlList.push(this.getHtml('...', '...', false));

var sum = this.now + this.space;

if (sum < this.total - this.space) {

for (var i = dec; i <= sum; i++) {

this.urlList.push(this.getHtml(this.url + '' + i, i, true));

}

}

}

this.urlList.push(this.getHtml('...', '...', false));

for (var i = this.total - this.space; i <= this.total; i++) {

this.urlList.push(this.getHtml(this.url + '' + i, i, true));

}

}

return this.urlList;

},

getHtml: function (link, text, flag) {

if (flag) {

return '

' + text + ''

} else {

return '

' + text + ''

}

},

show: function (sel) {

var dom = document.querySelector(sel);

if (!dom) {

return false;

}

var htm = '';

this.urlList.forEach(function (item) {

htm += item;

});

dom.innerHTML = htm;

}

}

var config = {

url: location.pathname + "?page=", // 基礎(chǔ)的url

space: 1, // 間隔 表示當前頁左右的位移顯示

total: 17, // 總數(shù)

now: 8, // 當前頁數(shù)

min: 10 // 最小顯示 小于等于10 會完全展開

};

pageIndex.init(config);

pageIndex.show("body");

總結(jié)

以上是生活随笔為你收集整理的html如何让条数按序号输出,JS 怎么控制页面序号较智能的生成?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。