简体   繁体   中英

bootstrap pagination not styled when added via javascript

I'm working on a website with multiple pages. I am adding them via javascript, but i can't understand why they don't get styled.

I've tried searching for some initialization code, and looked around the stackoverflow forums for at bit.

var pagination = document.getElementById('pagination');
    pagination.innerHTML = "";
    var firstPagination = document.createElement("li");
    if(page == 1){
      firstPagination.className += "page-item disabled";
    }else{
      firstPagination.className += "page-item";
    }
    var firstPaginationLink = document.createElement("a");
    firstPaginationLink.className += "page-item";
    firstPaginationLink.innerHTML = "«";

    pagination.appendChild(firstPagination);
    firstPagination.appendChild(firstPaginationLink);
    for(var i = 1; i < totalpages; i++){
      var selectPagination = document.createElement("li");
      if(page == i){
        selectPagination.className += "page-item active";
      }else{
        selectPagination.className += "page-item";
      }
      var selectPaginationLink = document.createElement("a");
      selectPaginationLink.className += "page-item";
      selectPaginationLink.innerHTML = i;
      pagination.appendChild(selectPagination);
      selectPagination.appendChild(selectPaginationLink);
    }
    var lastPagination = document.createElement("li");
    if(page == totalpages - 1){
      lastPagination.className += "page-item disabled";
    }else{
      lastPagination.className += "page-item";
    }
    var lastPaginationLink = document.createElement("a");
    lastPaginationLink.className += "page-item";
    lastPaginationLink.innerHTML = "&raquo;";

    pagination.appendChild(lastPagination);
    lastPagination.appendChild(lastPaginationLink);

Picture here of what i get vs what i want: http://prntscr.com/nky7pc

The html: http://prntscr.com/nky9bl

selectPagination.className += "page-item";

应该

selectPagination.className += "link-item";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM