Я создаю простое меню аккордеона с двумя способами навигации.Обмен переменными между более чем одной функцией
- При нажатии на шаге названии
- При нажатии на кнопки «Next/Prev» внутри шага.
Мой 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
Я читал это. Опять же, я попытался вывести из локального масштаба безрезультатно –