如何将setInterval周期设置为变量并删除等待时间?

我有一个表格,每行都有一个复选框。 选中复选框后,该函数将循环以更新每行的状态。

这是我的工作小提琴: http : //jsfiddle.net/qJdaA/2/我使用setInterval()来循环该函数。 由于表是动态的,我不知道列表将持续多长时间。 所以我将周期设置为变量index*4000 ,如下所示:

 $('#monitor').click(function () { $('#monitor').attr('disabled','true'); bigloop=setInterval(function () { var checked = $('#status_table tr [id^="monitor_"]:checked'); if (checked.index()==-1){ $('#monitor').attr('disabled','true'); }else{ (function loop(i) { $('#monitor').removeAttr('disabled'); //monitor element at index i monitoring($(checked[i]).parents('tr')); //delay setTimeout(function () { //when incremented i is less than the number of rows, call loop for next index if (++i < checked.length) loop(i); }, 3000); }(0)); //start with 0 } }, index*4000); 

然而,问题是它将等待第一个循环结束而不做任何事情。 假设列表中有10个项目,那么在执行任务之前它会等待40秒。 我怎样才能消除这个问题?

然后,如果在10个项目中,只检查了1行,我必须等待40秒才更新那一行,这是低效的。

我试图设置var clength = checked.length并使用它乘以4000.但它不起作用。 为什么以及如何做?

示例如何删除间隔

  

要么