我有一個計時器,我想在經過一段時間後提交表格。經過一段時間後自動提交表格
if (elapsedSeconds === 1800) {
document.getElementById("formid").submit();
}
我已用10替換1800測試,它在10秒後不提交表單。
我有一個計時器,我想在經過一段時間後提交表格。經過一段時間後自動提交表格
if (elapsedSeconds === 1800) {
document.getElementById("formid").submit();
}
我已用10替換1800測試,它在10秒後不提交表單。
聽起來你想用setTimeout()代替setInterval()。嘗試使用setTimeout(function(){document.getElementById("formid").submit();},1800000)
謝謝你的作品。儘管1800在ms中,所以我會將其轉換爲秒。 – frosty 2015-04-03 04:03:09
進行編輯。很高興我能幫上忙 – 2015-04-03 04:04:59
if(elapsedSeconds==1800){...}
需要在updateTimer
方法內。否則,你只會在頁面加載後執行一次,而不會再次執行。
否則,考慮使用一個setTimeout
並保存自己櫃檯的麻煩:如果您需要取消它,存儲參考
setTimeout(function(){
document.getElementById('formid').submit();
}, 30 * 60e3 /* 30 minutes */);
:
var to = setTimeout(...);
/* later on */
clearTimeout(to); // stops the timeout from executing (assuming it hasn't already)
你能分享更多的周邊的代碼請? – jrubins 2015-04-03 03:52:52
這是:http://puu.sh/gZEPm/2ad02ef11e.png – frosty 2015-04-03 03:55:57
@BradChristie工作,謝謝。 – frosty 2015-04-03 04:01:24