首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PHP和JavaScript显示/禁用按钮

使用PHP和JavaScript显示/禁用按钮
EN

Stack Overflow用户
提问于 2016-07-02 16:23:26
回答 2查看 723关注 0票数 1

当UNIX时间戳到达<= 0时,我将如何禁用/启用一个按钮。

我使用AJAX来连续每250 to调用一个..php文件。在这个..php文件中,我通过比较(在UNIX中)现在的时间和我上一次按按钮(使用MySQL数据库)的时间,来检查上一次操作是否是90秒。

比较是通过减去时间,它是按现在的时间。

当UNIX时间戳上一次按下按钮后的时间小于或等于0秒时,我想启用该按钮。

PHP和JavaScript之间的合作是一个挑战,我知道,但我也知道有一些方法可以做到这一点。

提前谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-07-02 16:51:09

根据脚本的内容,您可以使用jquery完成这一任务。与调用ajax不同,您可以为时间分配一个属性,然后使用jquery setInterval函数将时间减少1秒,然后检查时间是否小于0?示例:

HTML:

代码语言:javascript
复制
<input type='submit' id='button' name='button' data-time='(using php, put the seconds in here' />

Jquery

代码语言:javascript
复制
$(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);
});
票数 0
EN

Stack Overflow用户

发布于 2016-07-02 16:49:50

您只需使用javascript或jQuery通过更改按钮的disabled属性来禁用按钮。您也可以使用javascript将其更改回。

示例:document.getElementById("myBtn").disabled = true;

在这里阅读更多信息:disabled.asp

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38162170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档