加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

MVC 之 Ajax 分页查询数据

发布时间:2020-12-16 01:53:27 所属栏目:百科 来源:网络整理
导读: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="pre
<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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读