AJAX實現開源中國分頁

來源:互聯網
上載者:User

/// <summary>
    /// 仿造開源中國的分頁,分頁介面類似URL分頁
    /// 1 [2] [3] [4] [100]
    /// qq:Zr、還有點BUG沒修正
    /// <param name="currentIndex">當前索引</param>
    /// <param name="count">頁數</param>
    /// <param name="url">跳轉的頁面</param>
    /// <param name="classname">樣式名</param>
    /// <returns></returns>
    public string pagIng(int currentIndex, int count, string url, string classname)
    {
        int rightNum = 11; int step = 3;
        if (step <= 0 || currentIndex <= 0)
        {
            return null;
        }
        int LeftNum = 0; StringBuilder sb = new StringBuilder();
        if (currentIndex - step <= 1)
            LeftNum = 2;
        else
        {
            LeftNum = currentIndex - step;
            rightNum = currentIndex + (2 * step + 1) > count ? count:currentIndex + (2 * step + 1); 
            if (currentIndex + step > count)
            {
                rightNum = count;
            }
        }
        if (rightNum > count)
        {
            rightNum = count;
        }
        sb= currentIndex == 1 ? sb.Append("<span class=/"'" + classname + "'/">" + 1 + "</span>") : sb.Append("<span   class=/"'" + classname + "'/"><a name='" + url + "=1'>[" + 1 + "]</a></span>");
        for (int i = LeftNum; i < rightNum; i++)
        {
            sb = i == currentIndex ? sb.Append("<span class=/"'" + classname + "'/">" + i + "</span>") : sb.Append("<span  class=/"'" + classname + "'/"><a name='" + url + "=" + i + "'>[" + i + "]</a></span>");
        }
        if(count!=1)
        sb = currentIndex == count ? sb.Append("<span class=/"'" + classname + "'/">" + count + "</span>") : sb.Append("<span  class=/"'" + classname + "'/"><a name='" + url + "=" + count + "'>[" + count + "]</a></span>");
        return sb.ToString();
        //Response.End();
    }

這樣來調用

  int currentIndex = Convert.ToInt32(Request.QueryString["pid"]);
        int count = c1.bb() % pagesize == 0 ? c1.bb() / pagesize : c1.bb() / pagesize + 1;
       string str= pagIng(currentIndex, count, "?pid", "");

前台就簡單了啊

用的JQUERY

$("a").click(function(){
    var pid=$(this).attr("name");
  $(this).css("style","cursor:hand");
    $.get(pid,function(data,state){ $("#DIV1").empty().append(data)});

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.