首页 > 开发 > AJAX > 正文

基于AJAX的分页类实现代码

2024-09-01 08:29:24
字体:
来源:转载
供稿:网友
代码如下:
/**
* <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> 加载数据,请稍后...</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();
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表