bootstrap-paginator设置使用Bootstrap v3版本的样式

 开始使用时,我的Bootstrap版本是v3.3.7,仿着写完之后没有样式效果,看了源码才知道,3.3.7的版本的.pagination没有设置ul,是.pagination > li写的。

bootstrap-paginator中做了适配,在57行左右,"if (version > 2 && !this.$element.is("ul"))",这句需要把元素卸载ul上。

this.$element = $(element);

var version = (options && options.bootstrapMajorVersion) ? options.bootstrapMajorVersion : $.fn.bootstrapPaginator.defaults.bootstrapMajorVersion,
    id = this.$element.attr("id");

if (version === 2 && !this.$element.is("div")) {

    throw "in Bootstrap version 2 the pagination must be a div element. Or if you are using Bootstrap pagination 3. Please specify it in bootstrapMajorVersion in the option";
} else if (version > 2 && !this.$element.is("ul")) {
    throw "in Bootstrap version 3 the pagination root item must be an ul element."
}

 

 

Html代码如下,版本2,会把id="example"写在div中,如果用版本3,需要这样写:

<div>
  <ul id="example"></ul>
</div>

 

Javascript代码

var options = {
    bootstrapMajorVersion: 3, //版本,这里设置为3,大于2即可
    currentPage: @ViewBag.PageIndex,//当前页
    totalPages: $("#totalpage").val(),//总页数
    numberofPages: 10,//显示的页数

    itemTexts: function (type, page, current) { //修改显示文字
        switch (type) {
            case "first":
                return "第一页";
            case "prev":
                return "上一页";
            case "next":
                return "下一页";
            case "last":
                return "最后一页";
            case "page":
                return page;
        }
    }, onPageClicked: function (event, originalEvent, type, page) { //异步换页
        //请求加载数据
    }
};

$("#example").bootstrapPaginator(options);

 

转载于:https://www.cnblogs.com/dafeifei0218/p/7340254.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值