你可以用取決於劇本是關於什麼的jQuery做到這一點。與其調用ajax,你可以指定一個屬性的時間,然後使用jquery setInterval函數將時間減少1秒,然後檢查時間是否小於0? 實施例:
HTML:
<input type='submit' id='button' name='button' data-time='(using php, put the seconds in here' />
Jquery的
$(document).ready(function() {
var timer = setInterval(function() {
var current = $("#button").data('time');
// get the current value of the time in seconds
var newtime = current - 1;
if (newtime <= 0) {
// time is less than or equal to 0
// so disable the button and stop the interval function
$("#button").prop('disabled', true);
clearInterval(timer);
} else {
// timer is still above 0 seconds so decrease it
$("#button").data('time', newtime);
}
}, 1000);
});