我試圖在應用程序截止時間結束時禁用「應用」按鈕。我使用了PHP,並且我成功地在每個按鈕上獲得了時間。現在不同的時間是在不同的按鈕上打印。當時間消失時,使用PHP和JavaScript禁用按鈕
<td><input type='submit' value='Apply' id='button' name='button' date-time='$closedate' /></td>
我使用的jquery/javascript來禁用按鈕過期時間(應用程序的截止日期之後)之後,它不能禁用和它始終啓用。
在下面的代碼中,我用於禁用按鈕的代碼,但它不起作用。
<script>
$(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);
});
</script>
我得到了我使用php變量$ closedate存儲在mysql數據庫中的截止日期。像\t 2017-03-17。 \t $ closedate = $ row_op ['closedate']; –
在這種情況下,您的javascript將會成爲問題,您需要將closedate轉換爲一個值,該值表示現在和該日期之間的差異,以秒爲單位。這將允許您的JavaScript倒計時,基於當前的邏輯。 :看到這個鏈接獲得在幾秒鐘內的差異http://stackoverflow.com/questions/5988450/difference-between-2-dates-in-seconds –