显示/禁用按钮与PHP和JavaScript
Show/disable button with PHP and JavaScript
当UNIX时间戳达到<= 0时,我该如何禁用/启用按钮呢?
我使用AJAX每隔250毫秒连续调用一个.php文件。在这个.php文件中,我通过比较(在UNIX中)现在和上次按下按钮(使用MySQL数据库)的时间来检查自上次操作以来是否已经过了90秒。
比较是通过将按下的时间减去现在的时间来完成的。
我想启用按钮时,当UNIX时间戳,当有小于或等于0秒的按钮上次按下
我知道PHP和JavaScript之间的合作是一个挑战,但我也知道有很多方法可以做到这一点。
您可以根据脚本的内容使用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);
});
你可以使用javascript或jQuery通过改变它的disabled
属性来禁用按钮。你也可以用javascript把它改回来。
示例:document.getElementById("myBtn").disabled = true;
阅读更多:http://www.w3schools.com/jsref/prop_pushbutton_disabled.asp
相关文章:
- PHP Javascript显示/隐藏按钮不工作
- php javascript代码从javascript调用php函数
- 如何在php/javascript中制作定时器和警报
- 带有数据输入的PHP/JavaScript web交互式图谱
- PHP - Javascript integration?
- 从复选框 ajax php javascript 中检索值
- 验证此图像验证码.Jquery PHP & javascript.
- Facebook PHP+JavaScript-在页面加载之前导航时出现异常
- PHP/JavaScript-检测当前打开页面的用户
- Php-Javascript-我如何知道哪些页面是彩色的,哪些是黑白的
- PHP+Javascript解析这两个响应
- 创建php/javascript倒计时计时器时出现问题
- 转换“;2012年7月15日星期日00:00:00 GMT+0700(东南亚标准时间)“;到php/javascript
- 与php/javascript函数调用混淆
- 从下拉框中获取选定的值,并使用来填充文本框php javascript
- 如何使用php+javascript更改HTML表的内容
- Php javascript不显示数据
- PHP/JavaScript MP3播放器,用于采样和销售歌曲
- Integration PHP + Javascript
- Adsense Onclick(php, javascript)