你好,我有一個通過PHP執行定時器/ HTML這樣如何使用jquery問題重新啓動javascript函數
// timer
print "<script>countdown();</script>";
但是我有一個jQuery的警告對話框看起來像這樣,我想對於JavaScript函數重新啓動他們點擊關閉按鈕
// Create timeout warning dialog
$('body').append('<div title="Timeout"</div>');
$('#sessionTimeout-dialog').dialog({
autoOpen: false,
width: 600,
modal: true,
closeOnEscape: false,
open: function(event, ui) { $(".dialog").hide(); },
buttons: {
// Button two - closes dialog and makes call to keep-alive URL
"Continue Session": function() {
$(this).dialog('close');
clearTime();
$.ajax({
type: 'POST',
url: o.keepAliveUrl
});
countdown(); //I call the javascript function in hopes of making it go again
}
}
});
但是我似乎無法使計時器居然重啓一次的按鈕點擊後繼續。這裏是我的計時器代碼,我做錯了什麼?我調用JavaScript函數的按鈕關閉後,但沒有任何反應它只是爲負數
// set minutes
var mins = 2;
// calculate the seconds (don't change this! unless time progresses at a different speed for you...)
var secs = mins * 60;
function countdown() {
setTimeout('Decrement()',1000);
}
function Decrement() {
if (document.getElementById) {
minutes = document.getElementById("minutes");
seconds = document.getElementById("seconds");
// if less than a minute remaining
if (seconds < 59) {
seconds.value = secs;
} else {
minutes.value = getminutes();
seconds.value = getseconds();
}
secs--;
setTimeout('Decrement()',1000);
}
}
function getminutes() {
// minutes is seconds divided by 60, rounded down
mins = Math.floor(secs/60);
return mins;
}
function getseconds() {
// take mins remaining (as seconds) away from total seconds remaining
return secs-Math.round(mins *60);
}
什麼是'controlRedirTimer'? – Blender
@Blender它是一個功能的嘗試,我刪除它,因爲它不相關了,抱歉的混亂 – Squirtle