怎么不能實(shí)現(xiàn)呢
<!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(){
?????? // 計(jì)時(shí)開始
????????? 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="發(fā)送驗(yàn)證碼" >
??? <input type="button" id="receive" >
</body>
</html>
2015-10-17
setInterval()調(diào)用出錯(cuò)。 正確的調(diào)用方式如下:
?? timer=setInterval('showTime()',500);??????? 或 ?? timer=setInterval(showTime,500);????????
定義和用法
setInterval() 方法可按照指定的周期(以毫秒計(jì))來(lái)調(diào)用函數(shù)或計(jì)算表達(dá)式。
setInterval() 方法會(huì)不停地調(diào)用函數(shù),直到 clearInterval() 被調(diào)用或窗口被關(guān)閉。由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的參數(shù)。
語(yǔ)法??? setInterval(code,millisec[,"lang"])?
參數(shù)???? 描述
code ? ?必需。要調(diào)用的函數(shù)或要執(zhí)行的代碼串。 ? ?
millisec ? ?必須。周期性執(zhí)行或調(diào)用 code 之間的時(shí)間間隔,以毫秒計(jì)。 ? ?