admin管理员组文章数量:1425699
My question is probably simple, but I'm only a week into programming, and I cant really understand the relative answers that I could find. So... need your Jedi help. How to disable a submit button for 10 seconds after the page is loaded? Thanks!
My question is probably simple, but I'm only a week into programming, and I cant really understand the relative answers that I could find. So... need your Jedi help. How to disable a submit button for 10 seconds after the page is loaded? Thanks!
Share Improve this question edited Apr 24, 2013 at 8:49 mplungjan 179k28 gold badges182 silver badges240 bronze badges asked Apr 24, 2013 at 8:42 user2309163user2309163 531 gold badge2 silver badges5 bronze badges 3- 2 have the button with the disabled tag, use a javascript setTimeout() timer for 10 seconds which after that period will change the button property to be not disabled. – Dave Commented Apr 24, 2013 at 8:44
- We can do it by using jquery ... use .hide() – Nipun Tyagi Commented Apr 24, 2013 at 8:44
- We can also do it without using jQuery at all – mplungjan Commented Apr 24, 2013 at 8:46
1 Answer
Reset to default 6You can use javascript like this
<input type="submit" id="submitButton" disabled="disabled" />
using
<script type="text/javascript">
window.onload=function() {
setTimeout(function(){
document.getElementById('submitButton').disabled = null;
},10000);
}
</script>
The following will additionally show a countdown in a container with ID="timeLeft" if you need one
<script type="text/javascript">
var countdownNum = 10;
window.onload=function() {
incTimer();
}
function incTimer(){
setTimeout (function(){
if(countdownNum != 0){
countdownNum--;
document.getElementById('timeLeft').innerHTML = 'Time left: ' + countdownNum + ' seconds';
incTimer();
} else {
document.getElementById('submitButton').disabled = null;
document.getElementById('timeLeft').innerHTML = 'Ready!';
}
},1000);
}
</script>
本文标签: phphow to disable a submit button for 10 seconds after the page is loadedStack Overflow
版权声明:本文标题:php - how to disable a submit button for 10 seconds after the page is loaded - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745410774a2657459.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论