DEMO
Để phân trang cho bảng như vậy, bạn hãy thực hiện như sau:
Bước 1. Đăng nhập Blogger, vào Design >> Edit HTML. Đặt đoạn code sau đây vào trước thẻ </head>.
- <script type="text/javascript">
- //<![CDATA[
- function Pager(tableName, itemsPerPage) {
- this.tableName = tableName;
- this.itemsPerPage = itemsPerPage;
- this.currentPage = 1;
- this.pages = 0;
- this.inited = false;
- this.showRecords = function(from, to) {
- var rows = document.getElementById(tableName).rows;
- // i starts from 1 to skip table header row
- for (var i = 1; i < rows.length; i++) {
- if (i < from || i > to)
- rows[i].style.display = 'none';
- else
- rows[i].style.display = '';
- }
- }
- this.showPage = function(pageNumber) {
- if (! this.inited) {
- alert("not inited");
- return;
- }
- var oldPageAnchor = document.getElementById('pg'+this.currentPage);
- oldPageAnchor.className = 'pg-normal';
- this.currentPage = pageNumber;
- var newPageAnchor = document.getElementById('pg'+this.currentPage);
- newPageAnchor.className = 'pg-selected';
- var from = (pageNumber - 1) * itemsPerPage + 1;
- var to = from + itemsPerPage - 1;
- this.showRecords(from, to);
- }
- this.prev = function() {
- if (this.currentPage > 1)
- this.showPage(this.currentPage - 1);
- }
- this.next = function() {
- if (this.currentPage < this.pages) {
- this.showPage(this.currentPage + 1);
- }
- }
- this.init = function() {
- var rows = document.getElementById(tableName).rows;
- var records = (rows.length - 1);
- this.pages = Math.ceil(records / itemsPerPage);
- this.inited = true;
- }
- this.showPageNav = function(pagerName, positionId) {
- if (! this.inited) {
- alert("not inited");
- return;
- }
- var element = document.getElementById(positionId);
- var pagerHtml = '<span onclick="' + pagerName + '.prev();" class="pg-normal"> « Prev </span> | ';
- for (var page = 1; page <= this.pages; page++)
- pagerHtml += '<span id="pg' + page + '" class="pg-normal" onclick="' + pagerName + '.showPage(' + page + ');">' + page + '</span> | ';
- pagerHtml += '<span onclick="'+pagerName+'.next();" class="pg-normal"> Next »</span>';
- element.innerHTML = pagerHtml;
- }
- }
- //]]>
- </script>
Bước 2. Đặt đoạn CSS sau đây vào trước dòng ]]></b:skin> để định dạng các thuộc tính cho phần phân trang:
- .pg-normal {
- color: red;
- font-weight: normal;
- text-decoration: none;
- cursor: pointer;
- }
- .pg-selected {
- color: black;
- font-weight: bold;
- text-decoration: underline;
- cursor: pointer;
- }
Lưu Template.
Bước 3. Khi tạo nội dung trong một bài viết nào đó, hãy sử dụng cấu trúc HTML cho bảng dưới dạng như sau (ở đây demo bảng có 3 cột và 9 dòng để phân trang thành 3 trang, bạn có thể vận dụng linh hoạt):
- <table id="results">
- <tr>
- </tr>
- <tr>
- </tr>
- <tr>
- </tr>
- <tr>
- </tr>
- <tr>
- </tr>
- <tr>
- </tr>
- <tr>
- </tr>
- <tr>
- </tr>
- <tr>
- </tr>
- <tr>
- </tr>
- </table>
- <script type="text/javascript"><!--
- var pager = new Pager('results', 3);
- pager.init();
- pager.showPageNav('pager', 'pageNavPosition');
- pager.showPage(1);
- //--></script>
Ở đoạn script trên thì số 3 biểu thị số dòng mỗi trang, bạn có thể điều chỉnh tùy theo trường hợp áp dụng của bạn.
ninest123 12.15
ReplyDeleteoakley sunglasses, louboutin shoes, michael kors outlet online, prada outlet, louis vuitton outlet online, oakley sunglasses, nike free, oakley sunglasses, replica watches, burberry outlet, christian louboutin, nike air max, tiffany jewelry, tiffany jewelry, ralph lauren outlet, ray ban sunglasses, burberry factory outlet, cheap jordans, longchamp outlet, michael kors, ralph lauren polo, michael kors outlet online, replica watches, gucci handbags, michael kors outlet, ray ban sunglasses, uggs on sale, michael kors handbags, nike outlet, nike air max, uggs on sale, uggs outlet, christian louboutin, prada handbags, uggs outlet, tory burch outlet, louis vuitton outlet, louboutin uk, longchamp bags, longchamp outlet, ray ban sunglasses, cheap oakley sunglasses, louis vuitton handbags, oakley sunglasses, louis vuitton, uggs on sale, michael kors outlet online, louis vuitton outlet
louboutin pas cher, timberland pas cher, nike trainers uk, true religion jeans, nike roshe run pas cher, nike air max pas cher, nike blazer pas cher, lunette ray ban pas cher, abercrombie and fitch, lululemon outlet, michael kors outlet online, michael kors, coach outlet store online, coach purses, new balance, nike air max, hollister uk, michael kors, lunette oakley pas cher, true religion outlet, nike tn pas cher, replica handbags, nike air max uk, longchamp soldes, nike free, longchamp pas cher, north face uk, ralph lauren pas cher, michael kors uk, north face pas cher, vanessa bruno pas cher, true religion outlet, polo ralph lauren uk, nike air force, converse, vans pas cher, nike roshe uk, burberry pas cher, sac guess pas cher, true religion outlet, nike air max uk, ray ban uk, hogan sito ufficiale, jordan pas cher, hermes pas cher, mulberry uk, polo lacoste pas cher, nike free pas cher, abercrombie and fitch UK
ReplyDeletesac louis vuitton, ugg,uggs,uggs canada, supra shoes, coach outlet, canada goose outlet, doke & gabbana, hollister, montre pas cher, pandora jewelry, swarovski uk, ugg pas cher, canada goose, juicy couture outlet, links of london uk, moncler uk, moncler, louis vuitton, canada goose jackets, louis vuitton uk, thomas sabo uk, barbour, moncler, moncler jackets, lancel, canada goose outlet, ugg,ugg australia,ugg italia, barbour jackets uk, canada goose, replica watches, karen millen uk, moncler, pandora jewelry, juicy couture outlet, swarovski jewelry, canada goose jackets, toms shoes, louis vuitton, marc jacobs, pandora charms, ugg uk, canada goose uk, canada goose pas cher, moncler outlet, bottes ugg pas cher, pandora uk, wedding dresses uk, moncler, moncler pas cher, sac louis vuitton, converse shoes outlet
ReplyDeleteninest123 12.15