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); }
2.1m questions
2.1m answers
60 comments
57.0k users