두 가지 탐색 방법으로 간단한 아코디언 메뉴를 만듭니다. 스텝 내부 "다음/이전"버튼을 클릭하면, 단계 표제 둘 이상의 함수간에 변수 공유
- .
내 JS 코드는 다음과 같습니다
$(document).ready(function(){
// Click on TITLE
$(".step-title").click(function(){
var this_title = $(this).parents(".step").children(".step-title");
var this_content = $(this).parents(".step").children(".step-content");
var that_title = $(".step-title");
var that_content = $(".step-content");
if (this_title.hasClass("active"))
{
this_title.removeClass("active");
this_content.slideUp(200);
} else {
that_title.removeClass("active");
this_title.addClass("active");
that_content.slideUp(200);
this_content.slideDown(200);
}
});
// Click on BUTTON
$(".save").click(function(){
var this_title = $(this).parents(".step").children(".step-title");
var this_content = $(this).parents(".step").children(".step-content");
var that_title = $(".step-title");
var that_content = $(".step-content");
if (this_title.hasClass("active"))
{
that_title.addClass("active");
this_title.removeClass("active");
that_content.slideDown(200);
this_content.slideUp(200);
}
});
});
당신은 내가 따라서 두 기능의 루트에 같은 변수를 재사용하고 볼 수 있듯이 내 문제.
** 질문 ** 여러 변수에서 변수를 공유 할 수있는 방법이 있습니까?
함수의 로컬 범위 밖으로 가져갈 때 작동하지 않습니다.
도움 주셔서 감사합니다.
2 단어 : 가변 범위 : http://stackoverflow.com/questions/500431/what-is-the-scope-of-variables-in-javascript?rq=1 – Hazonko
나는 그것을 읽었다. 다시 말하지만, 지역 범위를 활용하지 않으려 고 노력했습니다 –