js 分页

来源:互联网 发布:软件开发费税率2016年 编辑:程序博客网 时间:2024/05/19 12:13
 

<%@ Page Xlanguage="VB" AutoEventWireup="false" CodeFile="Default4.aspx.vb" Inherits="aa_Default4" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

<style type="text/css">
.content{width:500px;background:#CCCCCC;margin:0px auto;}
.text{width:500px;}
.pages{width:500px;height:20px;background:#999900;text-align:center;}
</style>
</head>

<body>
<div class="content">
<center>这里是标题!</center>
<div id="text" class="text"></div>
<div id="pages" class="pages"></div>
</div>
    <input id="Text1" type="text" /><input id="Button1" type="button" value="button" Xonclick="s()"/>
</body>
</html>

<script type="text/javascript">

    //文章所有内容
    var content = '1234567890123456789012345678901234567890asdqwezxcrtyvbn';
    //当前页
    var pageIndex = 1;
    //每页文字个数
    var txtLength = 10;
    //总页数
    var countPages = 0;
    if ((content.length % txtLength) == 0) {
        countPages = parseInt(content.length / txtLength);
    } else {
        countPages = parseInt(content.length / txtLength) + 1;
    }
    //翻页
    var pagesTxt = "";
    //上一页
    function previous(currPage) {
        pageIndex--;
        init(document.getElementById('Text1').value);
    }
    //下一页
    function next(currPage) {
        pageIndex++;
        init(document.getElementById('Text1').value);
    }
    function pages() {
        pagesTxt = "&nbsp;&nbsp;";
        if (pageIndex != 1) {
            pagesTxt += "<a href='javascript:previous(" + pageIndex + ")' style='color:#000000'>上一页</a>";
        } else {
            pagesTxt += "<a href='javascript:;' style='color:#cccccc'>上一页</a>";
        }
        pagesTxt += "&nbsp;&nbsp;";
        if (pageIndex != countPages) {
            pagesTxt += "<a href='javascript:next(" + pageIndex + ")' style='color:#000000'>下一页</a>";
        } else {
            pagesTxt += "<a href='javascript:;' style='color:#cccccc'>下一页</a>";
        }
        return pagesTxt;
    }
    function init(txtLength) {
        document.getElementById("text").innerHTML = content.substr((pageIndex - 1) * txtLength, txtLength);
        document.getElementById("pages").innerHTML = "<font color='#ff0000'>" + pageIndex + "</font>" + "/" + countPages + pages();
    }
    init(txtLength);
    function s()
    { init(document.getElementById('Text1').value) }
</script>