รหัสแสดงบทความใน Thinkphp:
คัดลอกรหัสรหัสดังต่อไปนี้:
<div id="showContent">{$article.content|htmlspecialchars_decode}</div>
<div id="articlePages"></div>
รหัสการใช้งาน js:
คัดลอกรหัสรหัสดังต่อไปนี้:
<script type="text/javascript">
var obj = document.getElementById("showContent");
หน้า var= document.getElementById("หน้าบทความ");
//alert(obj.scrollHeight);
window.onload= ฟังก์ชัน()
-
var all=Math.ceil(parseInt(obj.scrollHeight)/ parseInt(obj.offsetHeight));
//รับจำนวนหน้าทั้งหมด โดยใช้ scrollHeight เป็นหลัก
Pages.innerHTML="รวม"+ ทั้งหมด +"หน้า";
สำหรับ(var i=1; i<=all;i++)
-
Pages.innerHTML +=" <a href=/javascript:showPage('"+i+"');> "+i+"</a>";
//กรอกเลขหน้าทั้งหมด
-
-
ฟังก์ชั่น showPage (pageIndex)
-
obj.scrollTop = (pageIndex-1)* parseInt(obj.offsetHeight);
-
</สคริปต์>
รหัสซีเอส:
คัดลอกรหัสรหัสดังต่อไปนี้:
#showContent {
สี:สีดำ;
ขนาดตัวอักษร: 16px;
ความสูง: 700px;
ล้น: ซ่อนเร้น;
-
#บทความหน้า {
การจัดแนวข้อความ: ขวา;
-