ここに私のコードの一部があります:
$('#monitor').click(function(){
setInterval(function(){
$('#status_table tr [id^="monitor_"]:checked').each(function () {
monitoring($(this).parents('tr'));
});
},15000);
});
monitoring
チェックボックスがオンになっているテーブルの各行に対して関数を呼び出したい。私が1つしか持っていない場合、それは正常に機能しています。しかし、複数あると、ごちゃごちゃになります。つまり、テーブルに正しいステータスが追加されません。ここに私の機能がありますmonitoring
:
function monitoring($row) {
fbType = $row.find('td:nth-child(3)').html();
fbNum = $row.find('td:nth-child(4)').html();
eachStatus =$row.find('td:nth-child(5)').attr('id');
$('#ptest').append(fbType + ' '+ fbNum+' '+ eachStatus +'<br>');
$.post('/request', {inputText: fbNum,key_pressed: fbType.toString()}).done(function (reply) {
if (reply == "on") {
$('#status_table tr #'+eachStatus).empty().append("on");
} else if (reply =="off") {
$('#status_table tr #'+eachStatus).empty().append("off");
}
});
}
各行の関数呼び出しを遅らせるにはどうすればよいですか? 私は次のことを試しました
$('#monitor').click(function(){
setInterval(function(){
$('#status_table tr [id^="monitor_"]:checked').each(function () {
setTimeout(function(){
monitoring($(this).parents('tr'));
});
},1000);
},15000);
});
しかし、div #ptest が表示されますundefined
。