Updating Table with Refresh

前端 未结 2 1518
后悔当初
后悔当初 2021-01-26 11:33

I have a jquery app which consist of a table. The table has a time field and some number fields. I want to basically increment the values every 3 seconds. So i was thinking of c

2条回答
  •  清酒与你
    2021-01-26 12:37

    Here is a way. Add classes to the cells that need updating:

    Lebron James
    08:00
    27
    11
    10
    

    In this example, the class updateMeInt means it is a simple integer, and updateMeTime means it is a time value.

    Then your update function would iterate through each cell with these classes and increment:

    function UpdateFunction(){
        $(".updateMeInt").each(function(index){
           var cur = parseInt($(this).text(), 10);
           $(this).text(cur + 1);    
        });
    
        $(".updateMeTime").each(function(index){
            var cur = $(this).text().split(":");    
            var sec = parseInt(cur[1], 10);        
            var min = parseInt(cur[0], 10);
    
            sec = sec + 3;
            if (sec >= 60){
                 sec = 0
                 min = min + 1;
            }
            $(this).text(pad(min) + ":" + pad(sec)); 
    
        });
    } 
    

    Updated FIDDLE

提交回复
热议问题