亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

代碼只能執行一次如何修改?

<!doctype html>

<html>

<head>

? ? <meta charset="UTF-8">

<title>Document</title>


</head>

<body>

<input type="button" id="send" value="發送驗證碼">


<script type="text/javascript">

window.onload=function(){

? ?var send=document.getElementById('send'),

? ? ? ?times=60,

? ? ? ?timer=null;

? ? ? ?

? ?send.onclick=function(){

? ? timer = setInterval(countDown,1000);


? ?}


? ? ? ? function countDown(){

? ? ? ? ?times-=1;

send.setAttribute('disabled','disabled');

? ? ? ? ?if(times<0){

? ? ? ? ? clearInterval(timer);?

? ?send.setAttribute("value","重新發送驗證碼");

? ?send.removeAttribute('disabled');

? ? ? }

? ? ? ? ?else

? ? ? ? ?{

? ? ? ?send.setAttribute("value",times+"秒后重試");

? ? ? ? ?}

? ? ? ? }?

}

</script>

? ? ??


</body>

</html>


正在回答

2 回答

你可以這樣:

??? window.onload=function(){
?? ???? var send=document.getElementById('send'),
?? ???????? times=60,
?? ???????? timer=null;
?? ???? send.onclick=function(){
?? ?????? // 計時開始
???????? ?
???????? timer = setInterval(function(){
???????????? send.value = times + "秒后重試";
???????????? send.disabled = "disabled";
???????????? times--;
???????????? if(times == 0){
???????????????? send.value = "發送驗證碼";
???????????????? send.disabled = "";
???????????????? clearInterval(timer);
???????????????? times = 60;
??????????? }
???????? },1000);
?? ???? }
?? ?}

0 回復 有任何疑惑可以回復我~
if(times<0){
???clearInterval(timer);?
???send.setAttribute("value","重新發送驗證碼");
???send.removeAttribute('disabled');
這里加??//??times=60;??//?第二次無效是因為times已經是-1了。直接成立if條件停止了。要重置times為60.
?}else


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

代碼只能執行一次如何修改?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號