This question already has an answer here:(这个问题已经在这里有了答案:)
Look at the following code.(看下面的代码。)
for(i=1;i<=10;i++){ $('#field'+i).click(function(){ alert(i); }); }
i
Use let to limit your i within the loop scope.(使用let将您的i限制在循环范围内。)
let
for(let i=1;i<=10;i++){ setTimeout(function(){ console.log(i) }, 500); }
1.4m articles
1.4m replys
5 comments
57.0k users