for ( var i=10;i>=0;i-- ) {
(function(){
var pos = i;
setTimeout(function(){
alert(pos);
document.getElementById("original").style.marginLeft = -( pos ) + "px";
}, ( pos + 1 ) * 10 );
})();
}alert依次弹出为
0,1,2,3,4,5,6,7,8,9,10令我大感愕然,意外,难道我要推翻自己的javascript知识了,明明是循环递减嘛晕啊
(function(){
var pos = i;
setTimeout(function(){
alert(pos);
document.getElementById("original").style.marginLeft = -( pos ) + "px";
}, ( pos + 1 ) * 10 );
})();
}alert依次弹出为
0,1,2,3,4,5,6,7,8,9,10令我大感愕然,意外,难道我要推翻自己的javascript知识了,明明是循环递减嘛晕啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货