We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
请问轮播图JS代码中 for(var i = 0; i < 4; i++){ (function (j) { li[j].addEventListener('click',function () { clearInterval(timer); index = j; moveTo(index); timer = setInterval(disPlay,2000); }) }(i)) } 应该如何理解呢?j是如何来的,以及“(i)”的意义是什么呢?
The text was updated successfully, but these errors were encountered:
立即执行函数,把i传给j。轮播图是给每一个li添加点击事件,点击事件是延迟执行,而for循环是立即执行。如果没有立即执行函数(function(j){//******})(i),当点击事件触发时,for循环已经结束了,每一个的index已经变成2了。通过立即执行函数及时地把i传进去。
Sorry, something went wrong.
No branches or pull requests
请问轮播图JS代码中
for(var i = 0; i < 4; i++){
(function (j) {
li[j].addEventListener('click',function () {
clearInterval(timer);
index = j;
moveTo(index);
timer = setInterval(disPlay,2000);
})
}(i))
}
应该如何理解呢?j是如何来的,以及“(i)”的意义是什么呢?
The text was updated successfully, but these errors were encountered: