复制代码 代码如下:
/**
* <p>pagination.js
* <p>通用的基于AJAX的分页类
* @author jeanwendy
* @version 1.0
*/
var paginationIndex = 0;
var pagination = function(trTemplatId) {
    $().ajaxStart(function() {
        $.blockUI({
            message : '<table><tr><td style="vertical-align :bottom"><font size=2pt>&nbsp;加载数据,请稍后...</font></td></tr></table>'
        });
    }).ajaxStop($.unblockUI);

    paginationIndex = paginationIndex + 1;
    this.id = paginationIndex;
    this.trTemplatId = trTemplatId;
    this.pageNo = 1;
    this.pageSize = 10;
    this.beforeQuery = null;
    this.afterQuery = null;
    this.url = null;
    this.params = null;
    this.templat = null;
    this.childrenCount = null;

    this.setPageNo = function(pageNo) {
        if (pageNo != null)
            this.pageNo = pageNo;
    }
    this.setPageSize = function(pageSize) {
        if (pageSize != null)
            this.pageSize = pageSize;
    }
    this.setBeforeQuery = function(fn){
        this.beforeQuery = fn;
    }
    this.setAfterQuery = function(fn){
        this.afterQuery = fn;
    }

    this.load = function(url, params) {
        //初始化(只在第一次查询时执行)
        if(this.templat == null && this.childrenCount == null){
            var templatObj = $('#'+this.trTemplatId);
            templatObj.parent().attr('id','tbody_id'+this.id);
            templatObj.removeAttr('id');
            templatObj.wrap("<div id='divTemplat'></div>");
            this.templat = $('#divTemplat').html();
            $('#divTemplat').remove();
            this.childrenCount = $('#tbody_id'+this.id).children().size();
        }
        //开始查询
        this.url = url;
        if(params == null) params = {};
        $.extend(params,{pageNo:this.pageNo,pageSize:this.pageSize});
        this.params = params;
        var thisObj = this;
        var options = {
            url : url,
            data : params,
            async : false, //采用同步方式请求
            type : 'POST',
            dataType : 'json',
            error : function(xmlhttp, errInfo, e) { //请求出错处理:如:404等
                if (xmlhttp.status == 200) alert('您已经很长时间没有访问网站,请退出后重新登陆!');
                else alert('请求后台服务时发生错误:' + xmlhttp.status);
            },
            success : function(data){
                //删除上一次的数据
                $('#tbody_id'+thisObj.id).children().filter(':gt('+(thisObj.childrenCount-1)+')').remove();
                thisObj.pageList(data.data);
                thisObj.pageBar(data.total);
                if($.isFunction(thisObj.afterQuery)) thisObj.afterQuery();
            }
        };
        if($.isFunction(this.beforeQuery)) this.beforeQuery();
        $.ajax(options); //发送请求
    }

    this.pageList = function(data){
        var filedArr = this.templat.match(/\{[A-Za-z0-9_]+\}/ig);
        for(var i = 0;i < data.length;i++){
            var thisTemplat = this.templat;
            for(var j = 0;j < filedArr.length;j++){
                var key = filedArr[j].substring(1,filedArr[j].length-1);
                if(key == 'NO_'){ //序号标识
                    var value = (this.pageNo-1)*this.pageSize + i + 1;
                    thisTemplat = thisTemplat.replace(new RegExp('\{'+key+'\}','gm'),value);
                }else{
                    var value = data[i][key];
                    if(typeof(value) != "undefined" && value == null) value = '';
                    thisTemplat = thisTemplat.replace(new RegExp('\{'+key+'\}','gm'),value);
                }
            }
            $(thisTemplat).appendTo($('#tbody_id'+this.id));
        }
    }

    this.pageBar = function(total){
        var templatObj = $(this.templat);
        var delChildren = templatObj.children(':gt(0)');
        delChildren.remove();
        templatObj.children().attr('colspan',$(this.templat).children().size());
        templatObj.children().attr('align','right');
        var pageCount;
        if(total % this.pageSize == 0) pageCount = total/this.pageSize;
        else pageCount = parseInt(total/this.pageSize) + 1;
        if(pageCount == 0) pageCount = 1;
        var toolbar = "第"+this.pageNo+"/"+pageCount+"页("+total+"条记录)";
        if(this.pageNo == 1) toolbar = toolbar + "&nbsp;首页&nbsp;上页";
        else toolbar = toolbar + "&nbsp;<a href='' id='firstPage"+this.id+"'>首页</a>&nbsp;<a href='' id='prePage"+this.id+"'>上页</a>";
        if(this.pageNo == pageCount) toolbar = toolbar + "&nbsp;下页&nbsp;末页";
        else toolbar = toolbar + "&nbsp;<a href='' id='nextPage"+this.id+"'>下页</a>&nbsp;<a href='' id='lastPage"+this.id+"'>末页</a>";
        toolbar = toolbar + "&nbsp;每页<input style='text-align:center;width:25px;height:20px;border:1 solid black' type='text' id='pageSize"+this.id+"' value="+this.pageSize+" />条";
        toolbar = toolbar + "&nbsp;<input style='text-align:center;width:25px;height:20px;border:1 solid black' type='text' id='pageNo"+this.id+"' value="+this.pageNo+" />";
        toolbar = toolbar + "&nbsp;<input style='height:20px;border:1 solid black' id='goPage"+this.id+"' type='button' value='GO'>";
        templatObj.children().html(toolbar);
        $(templatObj.wrap("<div></div>").parent().html()).appendTo($('#tbody_id'+this.id));
        var thisObj = this;
        $('#firstPage'+thisObj.id).click(function(){
            thisObj.pageNo = 1;
            thisObj.load(thisObj.url,thisObj.params);
            return false;
        });
        $('#prePage'+thisObj.id).click(function(){
            thisObj.pageNo = parseInt(thisObj.pageNo) - 1;
            thisObj.load(thisObj.url,thisObj.params);
            return false;
        });
        $('#nextPage'+thisObj.id).click(function(){
            thisObj.pageNo = parseInt(thisObj.pageNo) + 1;
            thisObj.load(thisObj.url,thisObj.params);
            return false;
        });
        $('#lastPage'+thisObj.id).click(function(){
            thisObj.pageNo = pageCount;
            thisObj.load(thisObj.url,thisObj.params);
            return false;
        });
        $('#pageSize'+thisObj.id).keydown(function(e){
            if(e.keyCode==13) {
                var v = $('#pageSize'+thisObj.id).val();
                if(!isIntGreatZero(v) || v == '0'){
                    alert('您输入显示条数不合法,请重新输入!');
                    $("#pageSize"+thisObj.id).focus();
                    return;
                }
                if(v > 200){
                    alert('您输入显示条数过大了,请重新输入!');
                    $("#pageSize"+thisObj.id).focus();
                    return;
                }
                thisObj.pageNo = 1;
                thisObj.pageSize = v;
                thisObj.load(thisObj.url,thisObj.params);
            }
        });
        $('#pageNo'+thisObj.id).keydown(function(e){
            if(e.keyCode==13) {
                $('#goPage'+thisObj.id).triggerHandler('click');
            }
        });
        $('#goPage'+thisObj.id).click(function(){
         var v = $('#pageNo'+thisObj.id).val();
            if(!isIntGreatZero(v) || v == '0'){
                alert('您输入页数不合法,请重新输入!');
                $("#pageNo"+thisObj.id).focus();
                return;
            }
         if(v > pageCount){
                alert('您输入页数大于总页数,请重新输入!');
                $("#pageNo"+thisObj.id).focus();
                return;
            }
            thisObj.pageNo = v;
            thisObj.load(thisObj.url,thisObj.params);
        });
    }

}
//true if the string is empty
var isEmpty = function(text) {
    var isEmpty = true;
    for (var i = 0; i < text.length; i++) {
        if (text.charAt(i) != ' ') {
            isEmpty = false;
            break;
        }
    }
    return isEmpty;
}
//true if the string is int and great than zero or equals zero
var isIntGreatZero = function(str) {
    if (isEmpty(str))
        return false;
    var temp1 = true;
    var temp2 = '0123456789';
    for (var i = 0; i < str.length; i++) {
        var c = str.charAt(i);
        if (temp2.indexOf(c) == -1) {
            temp1 = false;
            break;
        } else {
            if (c == '0' && i == 0 && str.length > 1) {
                temp1 = false;
                break;
            }
        }
    }
    return temp1;
}
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。