简单的js分页 免刷新 免跳转页面(即免&page=2页面跳转)

97 篇文章 1 订阅
76 篇文章 1 订阅


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Comment.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="Scripts/jquery.min.js"></script>
    <script type="text/javascript">
        //初始化
        $(function () {
            getList(1);//默认第1页
        });
        //清空
        function ClearTable() {
            $("#myTb").empty();
            var tbBody = "<tr><th>编号</th><th>评论</th><th>日期</th></tr>";
            $("#myTb").append(tbBody);
        }
        //查询数据(参数:页码)
        function getList(p) {         
            ClearTable();
            var size = 5;//每页几行数据
            var index = p;//页码
            $.ajax({
                type: "Post",
                url: "index.aspx/GetComment",
                data: "{'pageSize':" + size + ",'pageIndex':" + index + "}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    json = $.parseJSON(data.d);
                    for (var i in json) {
                        var tbBody = "";
                        tbBody += "<tr align='center'>";
                        tbBody += "<td>" + json[i].ComID + "楼</td>";
                        tbBody += "<td>";
                        tbBody += json[i].ComText;
                        if (json[i].ComPIC != "" && json[i].ComPIC != null) {
                            tbBody += "<br /><img width='50px' src='upload/" + json[i].ComPIC + "' />";
                        }
                        tbBody += "</td>";
                        tbBody += "<td>" + json[i].ComDate + "</td>";
                        tbBody += "</tr>";
                        $("#myTb").append(tbBody);
                    }
                    Pages(p);  //分页按钮
                },
                error: function (err) { }
            });
        }
        //分页按钮
        function Pages(p) {
            $("#pager").html("");                
            var size = 5;//每页几行数据
            var index = p;//页码
            $.ajax({
                type: "Post",
                url: "index.aspx/GetCommentCount",
                data: "{'name':'" + name + "'}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    var count = data.d;
                    if (count != null && count != 0) {
                        var pagecount = parseInt(count / size);//求总页数
                        var temp = count % size;//判断判断最后一页
                        if (temp > 0) {
                            pagecount = pagecount + 1;
                        }
                        var page = "";
                        for (var i = 0; i < pagecount; i++) {
                            if ((i + 1) == index) {
                                page += "<a style='color:red;'>[" + (i + 1) + "]</a>&nbsp;";
                            }
                            else {
                                page += "<a style='color:blue;' οnclick='getList(" + (i + 1) + ")'>[" + (i + 1) + "]</a>&nbsp;";
                            }
                        }
                        $("#pager").append(page);
                    }
                },
                error: function (err) { }
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <%--<h3>评论</h3>--%>
            <table id="myTb" style="width: 350px; border: solid 1px; font-size: small;" border="1" cellspacing="0" cellpadding="0"></table>
            <span id="pager"></span>
            <br />
            <a href="#" οnclick="getList(1)">刷新</a> | <a href="Comment.aspx" target="_top">我要评论</a>
        </div>
    </form>
</body>
</html>


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值