当UNIX时间戳到达<= 0时,我将如何禁用/启用一个按钮。
我使用AJAX来连续每250 to调用一个..php文件。在这个..php文件中,我通过比较(在UNIX中)现在的时间和我上一次按按钮(使用MySQL数据库)的时间,来检查上一次操作是否是90秒。
比较是通过减去时间,它是按现在的时间。
当UNIX时间戳上一次按下按钮后的时间小于或等于0秒时,我想启用该按钮。
PHP和JavaScript之间的合作是一个挑战,我知道,但我也知道有一些方法可以做到这一点。
提前谢谢。
发布于 2016-07-02 16:51:09
根据脚本的内容,您可以使用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);
});发布于 2016-07-02 16:49:50
您只需使用javascript或jQuery通过更改按钮的disabled属性来禁用按钮。您也可以使用javascript将其更改回。
示例:document.getElementById("myBtn").disabled = true;
在这里阅读更多信息:disabled.asp
https://stackoverflow.com/questions/38162170
复制相似问题