开发者

Using jQuery functions .each() and .live()

I am using the following jQuery code for table calculations....

$(document).ready(function() {
    var totalregfee = 0;
    $('.reg_fee').each(function(){
        totalregfee+= parseFloat($(this).html());
    });
    $('.total_regfee').html(totalregfee);
});

It works perfect when the page loads, but if I go to the next page or increase the data rows on page using tablesorter.pager, total doesn't get updated. How can I use jQuery .live() on the above code?

Please ask if you need more details, thanks for开发者_开发知识库 support.


You should make a function

var updateTotal = function(){
    var totalregfee = 0;
    $('.reg_fee').each(function(){
        totalregfee+= parseFloat($(this).html());
    });
    $('.total_regfee').html(totalregfee);
}

$(document).ready(function() {
    //call it on document ready
    updateTotal();
    //call it when you click a button
    $('#button').click(updateTotal);


});

Then call it on document ready and whenever you need to uopdate the total

To use it with tablesorter you should bind it to sortend (this works when you sort the table)

$('#idOfYourTable').bind("sortEnd", updateTotal);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜