如何在jquery中创建一个事件,如果它是最后一页,将在分页中触发。 这是我的代码
$(function () {
$('#myTable').jPaginate({
'max': 40,
'page': 1,
'links': 'buttons'
});
});
(function ($) {
$.fn.jPaginate = function (m) {
var n = {
'max': 50,
'page': 100,
'links': 'text'
};
var o = $.extend(n, m);
o.max = Math.max(1, o.max);
o.page = Math.max(1, o.page);
return this.each(function () {
var c = $(this);
if (c.is('table')) {
var d = c.find('tbody');
if (d.length == 0) {
d = c
}
var f = 0;
var g = 0;
d.find('tr').each(function (i) {
var a = $(this);
if (i % o.max == 0) {
f++
}
a.addClass('jPaginate-row-' + f);
if (f != o.page) {
a.hide()
}
if (i == 0) {
a.find('td,th').each(function () {
g += $(this).attr('colspan') != undefined ? 1 + parseInt($(this).attr('colspan'), 10) : 1
})
}
});
var h = c.find('tfoot');
if (h.length == 0) {
h = $('<tfoot></tfoot>');
h.appendTo(c)
}
var j = $('<th colspan="' + g + '"></th>');
$('<tr class="jPaginate-links-row"></tr>').append(j).appendTo(h);
if (f > 1) {
function showPage(a) {
d.find('tr').hide();
d.find('.jPaginate-row-' + a).css('display', 'table-row')
}
var k = '';
switch (o.links) {
case 'select':
for (var i = 1; i <= f; i++) {
k += '<option value="' + i + '"' + 'class="jPaginate-link-option' + (i == o.page ? ' jPaginate-link-option-selected" selected="selected' : '') + '">' + i + '</option>'
}
j.html('<select class="jPaginate-link-select">' + k + '</select>');
j.find('select').change(function () {
var a = $(this);
a.find('.jPaginate-link-option').removeClass('jPaginate-link-option-selected');
a.find('.jPaginate-link-option[value=' + a.val() + ']').addClass('jPaginate-link-option-selected');
showPage(a.val())
});
break;
case 'buttons':
j.html('<input class="jPaginate-link-button-first" type="button" value="«">' + '<input class="jPaginate-link-button-previous" type="button" value="<">' + '<input class="jPaginate-link-input" type="text" value="' + o.page + '">' + '<input class="jPaginate-link-button-next" type="button" value=">">' + '<input class="jPaginate-link-button-last" type="button" value="»">');
var l = j.find('.jPaginate-link-input');
l.change(function () {
var a = $(this);
var b = isNaN(a.val()) ? 1 : a.val();
a.val(Math.max(1, Math.min(f, b)));
showPage(a.val())
});
j.find('.jPaginate-link-button-first').click(function () {
l.val(1).change()
});
j.find('.jPaginate-link-button-last').click(function () {
l.val(f).change();
$('#r').html('<?=$total?>');
});
j.find('.jPaginate-link-button-previous').click(function () {
l.val(parseInt(l.val(), 10) - 1).change()
});
j.find('.jPaginate-link-button-next').click(function () {
l.val(parseInt(l.val(), 10) + 1).change()
});
break;
default:
for (var i = 1; i <= f; i++) {
k += '<a class="jPaginate-link-text' + (i == o.page ? ' jPaginate-link-text-active' : '') + '" href="#">' + i + '</a> '
}
j.html(k);
$('.jPaginate-link-text').click(function (e) {
e.preventDefault();
j.find('a').removeClass('jPaginate-link-text-active');
$(this).addClass('jPaginate-link-text-active');
showPage($(this).text())
});
break
}
}
}
})
}
})(jQuery);