码迷,mamicode.com
首页 > 编程语言 > 详细

javascript分页显示

时间:2017-06-21 13:43:16      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:ref   turn   code   count   cat   javascrip   replace   log   div   

 //根据条件查找数据
list = Stdqj.FindAll(where, "ID desc", "", (pageindex - 1) * 15, 15);
// 根据list查找的条件,查找list的总数(count)           
    ViewBag.total = Stdqj.FindCount(where);
//在传递参数中传递pageindex
//获取当前pageindex的值
                ViewBag.pageindex = pageindex;
            }
            return View(list);
 <div id="pager">
                <a href="javascript:;" onclick="goPage(1)">首页</a>
//pageindex如果大于1:pageindex=3(当前页=3)则存在第1页第2页,允许点击上一页
                @if (ViewBag.pageindex > 1)
                {
                    <a href="javascript:;" onclick="goPage(@(ViewBag.pageindex - 1))">上一页</a>
                }
                else
                {
                    <a href="javascript:;" class="noContent">上一页</a>
                }
//如果数量大于当前页pageindex*15则允许点击下一页/末页
                @if (ViewBag.total > ViewBag.pageindex * 15)
                {
                    <a href="javascript:;" onclick="goPage(@(ViewBag.pageindex + 1))" class="noContent">下一页</a>
//向上取整
                    <a href="javascript:;" onclick="goPage(@(Math.Ceiling(Convert.ToDouble(ViewBag.total)/15)))" class="noContent">末页</a>
                }
                else {
                    <a href="javascript:;" class="noContent">下一页</a>
                    <a href="javascript:;" class="noContent">末页</a>
                }
            </div>
            <script type="text/javascript">
    goPage = (function (page) {
        var s = window.location.href;
        if (/pageindex=/.test(s))
            s = s.replace(/pageindex=[0-9]*/, "pageindex=" + page);
        else
            s = s + "&pageindex=" + page;
        if (!/\?/.test(s))
            s = s.replace("&", "?");
        window.location.href = s;
    });
            </script>

 

javascript分页显示

标签:ref   turn   code   count   cat   javascrip   replace   log   div   

原文地址:http://www.cnblogs.com/shapaozi/p/7058909.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!