交作業。。
<!doctype html>
<html>
<head>
? ? <meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript">
window.onload=function(){
? ? var send=document.getElementById('send');
var main = document.body;
? ? ? ? times=5;
? ? ? ? timer=null;
// 方法一:
var input_out=document.createElement("input");
input_out.setAttribute("type","button");
input_out.setAttribute("id","out");
input_out.setAttribute("value","接收驗證碼");
main.appendChild(input_out);
? ? send.onclick=function(){
? ? ? // 計時開始?
timer=setInterval(function(){
var send_out=document.getElementById("out");
times--;
send_out.value=times+"秒后重試";
send_out.disabled=true;
if(times==0){
send_out.value="發送成功";
clearInterval(timer);
? ? send_out.disabled=false;
}?
},1000);
??
// 方法二: ??
// ?timer=setInterval(function(){
// ?times--;
// ?send.value=times+"秒后重試";
// ?// send.setAttribute("disabled","disabled");
// ?send.disabled=true;
// ?if(times==0){
// ?send.value="發送驗證碼";
// ?clearInterval(timer);
// ?// send.setAttribute("disabled","enable");
// ?send.disabled=false;
// ?}
// ?},1000);
//?
? ? ??
? ? }?
}
</script>
</head>
<body>
<input type="button" id="send" value="發送驗證碼">
</body>
</html>
2019-07-22
經驗+1