做的稍微完善一點點。
<!DOCTYPE?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<meta?name="viewport"?content="width=device-width,?initial-scale=1.0">
????<title>驗證碼按鈕倒計時</title>
</head>
<body>
????<input?type="button"?id='send'?value="發送驗證碼">
</body>
<script?type="text/javascript">
????var?send?=?document.getElementById('send');
????times?=?10;
????timer?=?null;
????//?console.log(send.value);
????if?(send.value?=?'發送驗證碼')?{
????????send.onclick?=?function?()?{
????????????var?tant?=?this;
????????????//?if?(timer)?{
????????????//?????clearInterval(timer);
????????????//?????timer?=?null;
????????????//?}
????????????timer?=?setInterval(function?()?{
????????????????times--;
????????????????if?(times?<=?0)?{
????????????????????tant.setAttribute('value',?'發送驗證碼');
????????????????????tant.disabled="";
????????????????????clearInterval(timer);
????????????????????times?=?10;
????????????????}?else?{
????????????????????tant.setAttribute('value',?times?+?'秒后重試');
????????????????}
????????????????console.log(times);
????????????},?1000);
????????????tant.setAttribute('disabled','true');
????????}
????}
</script>
</html>
2022-11-29
不錯 ,有想像
2021-10-29
很好很用心了,不錯