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

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

為什么上節講的時候可以timer = setInterval(autoPlay(), 2000);這樣寫,而我這樣寫就只能執行一次,就是1秒后沒不執行了

<!doctype?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<title>Document</title>
????<script?type="text/javascript">
????????window.onload=function(){
????????????var?send=document.getElementById('send'),
????????????second=document.getElementById('second'),
????????????????????times=5,
????????????????????timer=null;
????????????send.onclick?=?function?()?{
????????????????//?計時開始
?timer?=?setInterval(function?()?{
????????????????????autoPlay();
????????????????},?1000)
????????????}
????????????//自動播放
?function?autoPlay(){
????????????????if?(times?<=?0){
????????????????????times?=?5;
????????????????????send.disabled=false;
????????????????????send.value?=?'發送驗證碼';
????????????????????second.innerHTML=0;
????????????????????clearInterval(timer)
????????????????????return;
????????????????}
????????????????send.disabled=true;
????????????????send.value?=?'正在發送...';
????????????????second.innerHTML=times;
????????????????times--;
????????????}
????????}
????</script>
</head>
<body>
<input?type="button"?id="send"?value="發送驗證碼"><button?disabled><span?id="second">0</span>秒后重試</button>
</body>
</html>

為什么現在只能寫在function內了

正在回答

1 回答

timer?=?setInterval(autoPlay,?1000);???//直接這么寫的話autoPlay后面不能加()


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

舉報

0/150
提交
取消

為什么上節講的時候可以timer = setInterval(autoPlay(), 2000);這樣寫,而我這樣寫就只能執行一次,就是1秒后沒不執行了

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

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

幫助反饋 APP下載

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

公眾號

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