div超長內容分頁
阿新 • • 發佈:2017-08-07
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> "; } $("a").on("click", function (e) { var c = e.target; showPage(c.getAttribute(‘id‘)); }); });
div超長內容分頁