JavaScript的通用分頁程式

來源:互聯網
上載者:User

<Script type="text/JavaScript">
    function multi(num, PerPage, CurrPage, mpurl) {
    /**********參數說明*********
    num    總記錄數,由伺服器端程式提供
    PerPage    每頁記錄條數
    CurrPage    當前所在頁數
    mpurl    頁面URL(比如:list.php)
    ***************************/
   
    //計算總頁數
    if (num % PerPage == 0){
    pages = num / PerPage;
    } else {
    pages = Math.floor(num/PerPage) + 1;
    }
   
    //處理分頁URL地址,當已有變數參數時在其後加“&”,否則加“?”;
    //mpurl = mpurl.search(/?/)>0 ? mpurl + "&" : mpurl + "?";

        if (mpurl.search('/?/')>0)
        {
        mpurl=mpurl + "?";
        }
        else
        {
        mpurl=mpurl + "&";
        }
   
    document.write('共 ' + num + ' 條記錄 ');
   
    if (CurrPage == 1){
    document.write('首頁 上一頁');
    } else {
    //當前頁不是一頁時,顯示首頁及上一頁的連結
    document.write('首頁 上一頁');
    }
   
    if (CurrPage >= pages){
    document.write(' 下一頁 尾頁');
    } else {
    //當前頁不是尾頁時,顯示下一頁及尾頁的連結
    document.write(' 下一頁 尾頁');
    }
   
    document.write(' 頁次:' + CurrPage + '/' + pages + '頁 ' + PerPage + '條/頁 轉到:');
   
    //自動跳轉的分頁下拉式清單
    document.write("");
    for (i=1;i第' + i + '頁');
    } else {
        document.write('第' + i + '頁');
    }
    }
    document.write('');
    }

multi(123, 20,,'p.asp?id=1')

</script>
<script language="javascript">multi(123, 20,,'p.asp?id=1')</script>
在需要顯示分頁代碼的地方你只需要插入以下語句:multi(123, 20, 1, 'js_multipage.htm'),在設定具體參數時你只需將你的ASP或PHP程式的相關變數顯示在這裡就行了,如PHP中改為:</scriptlanguage="javascript">multi(<?=$total?>,<?=$perpage?>, <?=$page?>  , 'index.php?bid=1'</script

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.