1. 程式人生 > >div超長內容分頁

div超長內容分頁

nth innerhtml () cnblogs getattr article eth parse href

$(function () {
    function showPage(index) {
        var i = parseInt(index);
        obj.scrollTop = (i - 1) * parseInt(obj.offsetHeight);
    }
    var obj = document.getElementById("article");
    var pages = document.getElementById("pages");
    var allpages = Math.ceil(parseInt(obj.scrollHeight) / parseInt(obj.clientHeight));
    pages.innerHTML 
= "<b>共" + allpages + "頁</br>"; for(var i=1;i<=allpages;i++) { pages.innerHTML += "<a href=‘#‘ id="+i+">"+"第"+i +"頁"+"</a>&nbsp;"; } $("a").on("click", function (e) { var c = e.target; showPage(c.getAttribute(‘id‘)); }); });

div超長內容分頁