Home >Web Front-end >JS Tutorial >js achieves the effect of n seconds countdown before clicking can be achieved_javascript skills
When we register users, we often encounter that after clicking the button, there will be a 60-second countdown before you can continue to click. The countdown can also be displayed on the button. These 60 seconds are to prepare for everyone to "read the agreement carefully". How this function is implemented, the detailed code is shared with you below.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>倒计时然后才可以点击效果代码</title> <script type="text/javascript"> var s=4; function countsub() { var btnReg=document.getElementById("btnReg"); if(btnReg) { if(s<=0) { btnReg.value="同意"; btnReg.disabled=false; clearInterval(id); } else { btnReg.value="请仔细阅读协议(还剩"+s+"秒)"; s--; } } } var id = setInterval('countsub()',1000) </script> </head> <body> <textarea>注册协议</textarea> <input id="btnReg" type="button" value="同意" disabled="true" /> </body> </html>
I hope this article will be helpful to everyone learning JavaScript programming.