交作业。。
<!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>