HTML
<a class="btn btn-default" id="enterBtn" disabled style="margin-top:2rem" href="legalnewform.html"> 已知晓,进入法律咨询<span id="countDown" style="float:right">(5)</span> </a>
JS
<script type="text/javascript"> window.setTimeout("CountDown()", 1000); function CountDown() { var span = document.getElementById("countDown"); //改变span里面的值 var r = /[0-9]+/g; var a = span.innerText.match(r); span.innerText = "("+ ( a - 1)+")"; //判断是否减到了0 if (span.innerText == "(0)") { document.getElementById("enterBtn").removeAttribute("disabled"); span.innerText = ""; return; } window.setTimeout("CountDown()", 1000); } </script>
效果截图
标签:CountDown,span,js,倒计时,window,innerText,按钮,var,document From: https://www.cnblogs.com/zspwf/p/16737215.html