Home  >  Article  >  Web Front-end  >  js achieves the effect of n seconds countdown before clicking can be achieved_javascript skills

js achieves the effect of n seconds countdown before clicking can be achieved_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:24:361304browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn