Updating Table with Refresh

前端 未结 2 1560
后悔当初
后悔当初 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:32

    Try this code on interval function:

    $("#example > tbody tr").each(function(){
        var s = 0; //--- var for not increase 1st td ---
        $("td",this).each(function(){
            var data = $(this).html();
            if(/^[0-9]+\.?[0-9]*$/.test(data)){
              $(this).html(++data);   
            } else {
                if(s == 1) {
                  date = new Date();
                  var h = date.getHours();
                  var m = date.getMinutes();
                  if(m < 10) {m = '0'+m;} 
                  $(this).html(h+':'+m); 
                };
                s = 1; //--- after 1st td increase ---
    
          }
       });
    });
    

    JSFiddle

提交回复
热议问题