JavaScript+WebService分页


function StringBuilder(value) 
this.strings = new Array(""); 
this.append(value); 
// Appends the given value to the end of this instance. 
StringBuilder.prototype.append = function (value) 
if (value) 
this.strings.push(value); 
// Clears the string buffer 
StringBuilder.prototype.clear = function () 
this.strings.length = 1; 
// Converts this instance to a String. 
StringBuilder.prototype.toString = function () 
return this.strings.join(""); 

    <script type="text/javascript">
        Date.prototype.format = function(fmt) {
            var o = {
                "M+": this.getMonth() + 1,
       
                "d+": this.getDate(),
            
                "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12,
              
                "H+": this.getHours(),
            
                "m+": this.getMinutes(),
            
                "s+": this.getSeconds(),
           
                "q+": Math.floor((this.getMonth() + 3) / 3),
           
                "S": this.getMilliseconds()
            };
            var week = {
                "0": "\u65e5",
                "1": "\u4e00",
                "2": "\u4e8c",
                "3": "\u4e09",
                "4": "\u56db",
                "5": "\u4e94",
                "6": "\u516d"
            };
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            }
            if (/(E+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "\u661f\u671f" : "\u5468") : "") + week[this.getDay() + ""]);
            }
            for (var k in o) {
                if (new RegExp("(" + k + ")").test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                }
            }
            return fmt;
        }
       

        var currentPage = 1;
        var pageCount;
    function pageLoad()
    {
        CallWebMethod(currentPage);

    }
    function CallWebMethod(currentPage) {
        DolphinSites.WebService.GetAppInfo(currentPage,FillList);
    }
    function FillList(result) {
        var sBuilder = new StringBuilder();
        sBuilder.append('<table cellspacing="0" style="width: 100%; margin-left:4px">');
        for (var i = 0; i < result.length; i++) 
        {
            sBuilder.append('<tr><td rowspan="2" style="padding-top:1px ; padding-bottom:1px;border-bottom:1px solid #cecece;text-align: left;  width: 56px">');
            sBuilder.append('<a title="Google" href="AppsDetail.aspx?id=' + result[i].Id + '">');
            sBuilder.append('<img alt="Google" width="50px" src=' + result[i].Screenshot + ' /></a></td>');
            sBuilder.append(' <td style=" color:#cecece; font-size:13px; font-weight:700; padding-left:11px;">');
            sBuilder.append('<a href="AppsDetail.aspx?id=' + result[i].Id + '"');
            sBuilder.append(' style="text-decoration:none;color:#777777"><div style=" width:120px; height:20px;overflow:hidden">');
            sBuilder.append(result[i].AppName);
            sBuilder.append('</div></a><div style="font-size:8px">Release date:' + result[i].CreateTime.format("dd/MM/yyyy") + '</div></td><td align="right" style=" color:#F58600; font-size:10px;">');
            sBuilder.append(result[i].Price);
            sBuilder.append(' </td></tr><tr>');
            sBuilder.append(' <td colspan="2" style="text-align: left; font-size:12px;border-bottom:1px solid #cecece">');
            sBuilder.append('<div style="display:block; margin-top:0px;  margin-bottom:2px; line-height :12px; overflow:hidden;  height :60px; "><a href="AppsDetail.aspx?id=' + result[i].Id + '" style=" text-decoration:none; font-size:12px;" >');
            sBuilder.append('<a href="AppsDetail.aspx?Id=' + result[i].Id + '" style="text-decoration:none ">');
            sBuilder.append(result[i].Introduction);
            sBuilder.append('</a></div></td><td style="border-bottom:1px solid #cecece"></td>');
            sBuilder.append('<td style="border-bottom:1px solid #cecece; color:#72B311; text-decoration:none; width:20%; text-align:center;"><a href="AppsDetail.aspx?id=' + result[i].Id + '">');
            sBuilder.append('<img src="Images/Detail/imgNext.png" alt="MoreInfo" width="12" height="17" /></a></td></tr>');

        }
        sBuilder.append('</table>');
        document.getElementById("sPage").innerHTML = sBuilder;
        //GetPageCount();
    }
   
    function GetPageCount() {

       
     
        if (currentPage == 1) {

            document.getElementById('ImgPre').disabled = "disabled";
            document.getElementById('ImgPre').onclick = "";
        }
        if (currentPage == pageCount) {

            document.getElementById('ImgNext').disabled = "disabled";
            document.getElementById('ImgNext').onclick = "";

        }
    }
   
    function PageNation(page) {
        switch (page) {

            case "pre":
                currentPage -= 1;
                if (currentPage == 0) {
                    currentPage = 1;
                }
                CallWebMethod(currentPage) ;
                break;
            case "next":
                currentPage += 1;
                if (currentPage > pageCount) {
                    currentPage = pageCount;
                }
                CallWebMethod(currentPage);
                break;

        }
    }
    </script>
    
posted @ 2010-04-02 10:41  Blue Sky ......  阅读(384)  评论(0编辑  收藏  举报