开发者

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

开发者 https://www.devze.com 2023-04-04 23:10 出处:网络
I am using the following jQuery code for table calculations.... $(document).ready(function() { var totalregfee = 0;

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

精彩评论

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