微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MVC 之 Ajax 分页查询数据

<span style="font-size:18px;">//分页控件
        $(document).ready(function () {
            var pageSize = 10;
            var index;
            //分页控件
            $.jqPaginator('#pagination2',{
                pageSize: pageSize,totalCounts: 10,//总条数
                visiblePages: 10,currentPage: 1,prev: '<li class="prev"><a href="javascript:;">上一页</a></li>',next: '<li class="next"><a href="javascript:;">下一页</a></li>',page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',onPageChange: function (num,type) {
                    index = num;
                    getData();
                }
            });

            function getData() {
                $.post("@Url.Action("SelectBookStudent")",{
                    "pageSize": pageSize,"pageIndex": index,"type": "@(Request.QueryString["type"] ?? "False")"
                },function (result) {
                    var html = "";
                    if (result == null || result.list.length > 0) {
                        $('#pagination2').jqPaginator('option',{ totalCounts: result.total });
                        total = result.list.length;
                        $.each(result.list,function (i,item) {
                            //时间格式转换
                            var pa = /.*\((.*)\)/;
                            var StartDate = item.TKBeginDate.match(pa)[1].substring(0,10); //转换起始时间格式
                            var EndDate = item.TKEndDate.match(pa)[1].substring(0,10);//转换终止时间格式

                            var TKStartDate = getTime(StartDate); //起始日期
                            var TKEndDate = getTime(EndDate); //终止日期

                            var TKTestDate = TKStartDate.substring(0,10); //截取日期
                            var TKBeginTime = TKStartDate.substring(11,19); //截取起始时间
                            var TKEndTime = TKEndDate.substring(11,19);//终止时间

                            html += "<tr>";
                            html += "<td>" + (i + 1) + "</td>";
                            html += "<td>" + item.PlaceTest + "</td>";
                            html += "<td>" + TKTestDate + "</td>";
                            html += "<td>" + TKBeginTime + "</td>";
                            html += "<td>" + TKEndTime + "</td>";
                            html += "<td>" + item.RegNumTotal + "</td>";
                            html += "<td>" + item.RegNum + "</td>";
                            html += "<td>" + item.Explain + "</td>";
                            html += "<td><a href='javascript:void()' onclick='TKBook(\"" + item.TKCode + "\"," + item.Type + ")' >预约</a></td>";
                            html += "</tr>";

                        });
                        //$(".table-list tbody").html(html);
                        $("#select_tableList tbody").html(html);
                        $("#select_tableList tbody tr").click(function () { $(this).toggleClass("curr"); });
                        //$(".table-list tbody tr").click(function () { $(this).toggleClass("curr"); });
                    }
                })
            }
        });

    //时间转换 
 function getTime(/** timestamp=0 **/) {
 var ts = arguments[0] || 0;
 var t,y,m,d,h,i,s;
 t = ts ? new Date(ts * 1000) : new Date();
 y = t.getFullYear();
 m = t.getMonth() + 1;
 d = t.getDate();
 h = t.getHours();
 i = t.getMinutes();
 s = t.getSeconds();
 // 可根据需要在这里定义时间格式 
 return y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d) + ' ' + (h < 10 ? '0' + h : h) + ':' + (i < 10 ? '0' + i : i) + ':' + (s < 10 ? '0' + s : s);
 }
</span>

原文地址:https://www.jb51.cc/ajax/163004.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐