こんにちは、このようにphp/htmlを介して実行するタイマーがあります
// 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);
}