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

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

setTimeout里面第一行寫alert為什么不執行?

function animate(ball,distence,cb){

setTimeout(function(){

alert(1) //為什么alert不執行?

var marginLeft = parseInt(ball.style.marginLeft,10);


if(marginLeft === distence){

cb && cb();

}else{

if(marginLeft < distence){

marginLeft++;

}else{

marginLeft--

}

ball.style.marginLeft = marginLeft+'px';

animate(ball,distence,cb);

}

},13)

}


正在回答

2 回答

var ball1 = document.querySelector('.ball1');

var ball2 = document.querySelector('.ball2');

var ball3 = document.querySelector('.ball3');

function animate(ball,distence,cb){

setTimeout(function(){

alert(1) //為什么alert不執行?

var marginLeft = parseInt(ball.style.marginLeft,10);


if(marginLeft === distence){

cb && cb();

}else{

if(marginLeft < distence){

marginLeft++;

}else{

marginLeft--

}

ball.style.marginLeft = marginLeft+'px';

animate(ball,distence,cb);

}

},13)

}


animate(ball1,100,function(){

animate(ball2,200,function(){

animate(ball3,300,function(){

animate(ball3,150,function(){

animate(ball2,150,function(){

animate(ball1,150,function(){

//

})

})

})

})

})

})

上下我都跟老師的一樣的,不會報錯可以正常執行,但是沒有alert()

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

settimeout ?自啟 ?不執行 ?沒理由的 ? ?要么就是報錯 停止了 ? 要不你把上下代碼都貼出來看看

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

舉報

0/150
提交
取消
進擊Node.js基礎(二)
  • 參與學習       76735    人
  • 解答問題       242    個

本教程帶你攻破 Nodejs,讓 JavaScript流暢運行在服務器端

進入課程

setTimeout里面第一行寫alert為什么不執行?

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

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

幫助反饋 APP下載

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

公眾號

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