對table和ul實現(xiàn)js分頁示例分享
(function($) {
$.fn.tablepage = function(oObj, dCountOfPage, fresh_id) {
var dPageIndex = 1;
var dNowIndex = 1;
var sPageStr = "";
var dCount = 0;
var oSource = $(this);
var sNoSelColor = "#CCCCCC";
var sSelColor = "black";
var sFontColor = "white";
var nowIndex = 1;
change_page_content();
function change_page_content() {
// 取得資料筆數(shù)
dCount = oSource.children().children().length;
// 顯示頁碼
sPageStr = "<div class='ref'><a href='javascript:void(0)' id='fresh_"
+ fresh_id
+ "' onClick='fresh(this.id);' class='sx' style='color:#247AA9;'><span>刷新</span></a></div>";
sPageStr += " <div class='msdn'><a href='javascript:void(0)'>首頁</a><a href='javascript:void(0)'>上一頁</a><a href='javascript:void(0)'>下一頁</a><a href='javascript:void(0)'>尾頁</a></div>";
sPageStr += "<div class='txt'>"+"共"+Math.ceil(dCount / dCountOfPage)+"頁,當(dāng)前第"+"<strong>"+dNowIndex+"</strong>"+"頁"+"</div>";
oObj.html(sPageStr);
dPageIndex = 1;
// 過濾表格內(nèi)容
var rr=oSource.children().children("tr");
oSource.children().children("tr").each(function() {
// ==2
if (dPageIndex >= (((dNowIndex - 1) * dCountOfPage) + 1)
&& dPageIndex <= ((dNowIndex * dCountOfPage) )) {
$(this).show();
} else {
$(this).hide();
}
dPageIndex++;
});
// oSource.children().children("tr").first().show(); // head一定要顯示
if(dCount<=dCountOfPage){
var tt=$("#table_page_"+fresh_id).children('.msdn').children().each(function(i) {
if(i==2||i==3||i==0||i==1){
$(this).addClass("disabled");
}
});
}
else if(dNowIndex==Math.ceil(dCount / dCountOfPage)){
var tt=$("#table_page_"+fresh_id).children('.msdn').children().each(function(i) {
if(i==2||i==3){
$(this).addClass("disabled");
}
});
}else if(dNowIndex==1){
var tt=$("#table_page_"+fresh_id).children('.msdn').children().each(function(i) {
if(i==0||i==1){
$(this).addClass("disabled");
}
});
}
// 加入換頁事件
oObj.children().children().each(function() {
$(this).click(function() {
dNowIndex = $(this)[0].innerHTML;
if (dNowIndex == '首頁') {
dNowIndex = 1;
change_page_content();
nowIndex = dNowIndex;
}
if (dNowIndex == '尾頁') {
dNowIndex = Math.ceil(dCount / dCountOfPage);
change_page_content();
nowIndex = dNowIndex;
}
if (dNowIndex == '下一頁') {
if (nowIndex < Math.ceil(dCount / dCountOfPage)) {
dNowIndex = parseInt(nowIndex) + 1;
change_page_content();
nowIndex = nowIndex + 1;
}
}
if (dNowIndex == '上一頁') {
if (nowIndex > 1) {
dNowIndex = parseInt(nowIndex) - 1;
change_page_content();
nowIndex = nowIndex - 1;
}
}
});
});
}
};
})(jQuery);
<script type="text/javascript">
$(document).ready( function() {
var totalPage=$("ul li").length;
var total = Math.ceil($("ul li").length / 5);
var current = 1;
//var index =4;
if(totalPage>5){
$("ul li:gt(4)").hide();
$("#btnPrev").attr("class", "tabs-scroller-left-disabled").attr("disabled", "disabled").click( function() {
debugger;
$("#btnNext").attr("class", "tabs-scroller-right");
$("#btnNext").removeAttr("disabled");
current -= 1;
var tt=current;
$("ul li").show();
var indexStart = (current - 1);
var indexEnd = indexStart + 4;
$("li:lt(" + indexStart + "), li:gt(" + indexEnd + ")", $("ul")).hide();
if (current == 1){
$(this).attr("class", "tabs-scroller-left-disabled");
$(this).attr("disabled", "disabled");
}
});
$("#btnNext").click( function() {
debugger;
$("#btnPrev").attr("class", "tabs-scroller-left");
$("#btnPrev").removeAttr("disabled");
current += 1;
$("ul li").show();
var indexStart = (current - 1);
var indexEnd = current + 4 > $("ul li").length - 1 ? $("ul li").length - 1 : current +3;
$("li:lt(" + indexStart + "), li:gt(" + indexEnd +")", $("ul")).hide();
if (current+4 >= totalPage){
$(this).attr("class", "tabs-scroller-right-disabled");
$(this).attr("disabled", "disabled");
}
});
}else{
alert(1);
$("#btnPrev").attr("class", "tabs-scroller-left-disabled");
$("#btnNext").attr("class", "tabs-scroller-right-disabled");
}
});
</script>
- JS實現(xiàn)黑色風(fēng)格的網(wǎng)頁TAB選項卡效果代碼
- JS實現(xiàn)同一個網(wǎng)頁布局滑動門和TAB選項卡實例
- 利用js制作html table分頁示例(js實現(xiàn)分頁)
- 純css+js寫的一個簡單的tab標簽頁帶樣式
- JavaScript實現(xiàn)兩個Table固定表頭根據(jù)頁面大小自行調(diào)整
- Extjs中TabPane如何嵌套在其他網(wǎng)頁中實現(xiàn)思路及代碼
- 網(wǎng)頁開發(fā)中的容易忽略的問題 javascript HTML中的table
- 基于JavaScript實現(xiàn)在新的tab頁打開url
相關(guān)文章
js中apply()和call()的區(qū)別與用法實例分析
這篇文章主要介紹了js中apply()和call()的區(qū)別與用法,結(jié)合實例形式分析了apply()和call()的功能、區(qū)別、使用方法及相關(guān)操作注意事項,需要的朋友可以參考下2018-08-08
原生js實現(xiàn)表單的正則驗證(驗證通過后才可提交)
這篇文章主要給大家介紹了關(guān)于如何利用原生js實現(xiàn)表單的正則驗證,所有驗證都通過后提交按鈕才可用的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05
js實現(xiàn)文本框中輸入文字頁面中div層同步獲取文本框內(nèi)容的方法
這篇文章主要介紹了js實現(xiàn)文本框中輸入文字頁面中div層同步獲取文本框內(nèi)容的方法,實例分析了javascript操作dom元素的技巧,需要的朋友可以參考下2015-03-03
js實現(xiàn)帶關(guān)閉按鈕始終顯示在網(wǎng)頁最底部工具條的方法
這篇文章主要介紹了js實現(xiàn)帶關(guān)閉按鈕始終顯示在網(wǎng)頁最底部工具條的方法,是非常實用的javascript固定效果,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03
JS觸發(fā)事件event.target VS event.currentTarget實例
這篇文章主要介紹了JS觸發(fā)事件event.target VS event.currentTarget實例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-10-10

