js對文章內(nèi)容進行分頁示例代碼
更新時間:2014年03月05日 11:03:30 作者:
這篇文章主要介紹了使用js對文章內(nèi)容進行分頁的具體實現(xiàn),需要的朋友可以參考下
Thinkphp中文章顯示代碼:
<div id="showContent">{$article.content|htmlspecialchars_decode}</div>
<div id="articlePages"></div>
js實現(xiàn)代碼:
<script type="text/javascript">
var obj = document.getElementById("showContent");
var pages= document.getElementById("articlePages");
//alert(obj.scrollHeight);
window.onload= function()
{
var all=Math.ceil(parseInt(obj.scrollHeight)/ parseInt(obj.offsetHeight));
//獲取總頁數(shù),主要是應(yīng)用scrollHeight
pages.innerHTML="共"+ all +"頁";
for(var i=1; i<=all;i++)
{
pages.innerHTML +=" <a href=\javascript:showPage('"+i+"');> "+i+"</a> ";
//輸出所有頁碼
}
}
function showPage(pageIndex)
{
obj.scrollTop = (pageIndex-1)* parseInt(obj.offsetHeight);
}
</script>
css代碼:
#showContent {
color:black;
font-size: 16px;
height: 700px;
overflow: hidden;
}
#articlePages {
text-align: right;
}
復(fù)制代碼 代碼如下:
<div id="showContent">{$article.content|htmlspecialchars_decode}</div>
<div id="articlePages"></div>
js實現(xiàn)代碼:
復(fù)制代碼 代碼如下:
<script type="text/javascript">
var obj = document.getElementById("showContent");
var pages= document.getElementById("articlePages");
//alert(obj.scrollHeight);
window.onload= function()
{
var all=Math.ceil(parseInt(obj.scrollHeight)/ parseInt(obj.offsetHeight));
//獲取總頁數(shù),主要是應(yīng)用scrollHeight
pages.innerHTML="共"+ all +"頁";
for(var i=1; i<=all;i++)
{
pages.innerHTML +=" <a href=\javascript:showPage('"+i+"');> "+i+"</a> ";
//輸出所有頁碼
}
}
function showPage(pageIndex)
{
obj.scrollTop = (pageIndex-1)* parseInt(obj.offsetHeight);
}
</script>
css代碼:
復(fù)制代碼 代碼如下:
#showContent {
color:black;
font-size: 16px;
height: 700px;
overflow: hidden;
}
#articlePages {
text-align: right;
}
相關(guān)文章
List the Codec Files on a Computer
List the Codec Files on a Computer...2007-06-06
如何用JavaScript實現(xiàn)一個數(shù)組惰性求值庫
這篇文章主要介紹了如何用JavaScript實現(xiàn)一個數(shù)組惰性求值庫,對惰性求值感興趣的同學(xué),可以參考下2021-05-05
js 獲取后臺的字段 改變 checkbox的被選中的狀態(tài) 代碼
js 獲取后臺的字段 改變 checkbox的被選中的狀態(tài) 代碼,需要的朋友可以參考一下2013-06-06

