안녕 얘들 아 jquery에 작은 코드 조각이 있는데 문제가 있습니다. 두 번째 매개 변수 (i = 2 일 때)에 대한 루프 점프의 경우에는 무엇이 잘못되었는지 말할 수 있습니까?자바 스크립트 for 루프 "jump over value"
var items = $(".item").length;
var currentIndex = items;
place(currentIndex);
function place(index){
var s1 = Math.floor(items/2);
for (i = 1; i <= items; i++){
(function(i, index){
if (i <= s1){
var id = findNext(1, i);
console.log("i = " + i + " > id = " + id);
} else if (i > s1){
console.log("i = " + i);
}
})(i, index);
}
}
function findNext(index, times){
var result = index;
for (i = 1; i <= times; i++){
if (result == items){
result = 1;
} else {
result ++;
}
}
return result;
}
콘솔 출력이 표시됩니다 : 여기
코드입니다
i = 1 > id = 2
i = 3
i = 4
그래서 루프가 두 번째 매개 변수를 통해 이동을 위해 (내가 = 2 때) 당신이 나에게 무엇을 말할 수 잘못 것으로 보인다 ?