안녕하세요 저는 JavaScript가 처음이므로 작동하는 중첩 된 함수를 가져올 수 없습니다. 왜 그런지 이해하지 못합니다. 범위에 문제가 있습니까? 많은중첩 된 함수가 작동하지 않습니다.
$(document).ready(function(){
var prepocet = function(smer, poradie, pocet_obrazkov) {
if (smer == "left") {
if (pozicia - 1 < 1) {
return pocet_obrazkov
} else {
return pozicia - 1
};
} else {
if (pozicia + 1 > pocet_obrazkov) {
return 1
} else {
return pocet_obrazkov + 1
};
};
};
$("body").on("click", ".arrow", function() {
var smer = "left"
var pocet_obrazkov = $(this).parent().parent().next(".seria").children().length;
var pozicia = $(this).parent().parent().next(".seria").children().index(".on") + 1;
if ($(this).hasClass("arrow left")) {
smer = "left"
} else {
smer = "right"
};
var nova_pozicia = prepocet(smer, poradie, pocet_obrazkov);
$(this).parent().parent().next().children('#iddv img:nth-child(' + pozicia + ')').hide().addClass("off").removeClass("on");
$(this).parent().parent().next().children('#iddv img:nth-child(' + nova_pozicia + ')').show().addClass("on").removeClass("off");
});
});
맞아, 고마워! 변수 이름이 잘못되었다는 것을 어떻게 알 수 있습니까? – user3864092