怎么不能實現呢
<!doctype html>
<html>
<head>
??? <meta charset="UTF-8">
?<title>Document</title>
??? <style>
??????? #receive{display:none;}
???????
??? </style>
?<script type="text/javascript">
?window.onload=function(){
???? var send=document.getElementById('send'),
??????????? receive=document.getElementById('receive'),
???????? times=60,
???????? timer=null;
???? send.onclick=function(){
?????? // 計時開始
????????? timer=setInterval('showTime',500);????????
???? }
??????? function showTime(){
??????????? if(times>=0){
????????????? receive.style.display='block';
??????????????? receive.disabled ='false';
??????????????? receive.value=times+'秒后重試';
??????????????? times--;
????send.disabled='false';
??????????? }
??????????? else{????
????clearInterval(timer);
????? receive.style.display='none';
??????????? }
??????? }
?}
?</script>
</head>
<body>
?<input type="button" id="send" value="發送驗證碼" >
??? <input type="button" id="receive" >
</body>
</html>
2015-10-17
setInterval()調用出錯。 正確的調用方式如下:
?? timer=setInterval('showTime()',500);??????? 或 ?? timer=setInterval(showTime,500);????????
定義和用法
setInterval() 方法可按照指定的周期(以毫秒計)來調用函數或計算表達式。
setInterval() 方法會不停地調用函數,直到 clearInterval() 被調用或窗口被關閉。由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的參數。
語法??? setInterval(code,millisec[,"lang"])?
參數???? 描述
code ? ?必需。要調用的函數或要執行的代碼串。 ? ?
millisec ? ?必須。周期性執行或調用 code 之間的時間間隔,以毫秒計。 ? ?