Я хочу знать, есть ли у меня динамический способ комбинировать следующий код с коротким. У меня есть много if(). Is (: checked) {} else {}, могу ли я сделать что-то вроде if (this) .is (: checked), я пытаюсь использовать .closest(), но не знаю, я знаю, как его реализовать, также думая использовать массив? Вы в любом случае? оценить.У вас есть лучший динамический способ сократить сложный код jquery?
if ($("#diet_se").is(':checked')) {
\t \t $('#diet_voting').fadeIn();
\t \t \t $('#label_s2').addClass("label_se_active");
\t \t \t
\t \t \t jQuery("textarea[class*=expand1-99]").TextAreaExpander();//initialize the text expand
}else{
\t \t $('#diet_voting').fadeOut();
\t \t \t $('#label_s2').removeClass("label_se_active"); \t \t
}
if ($("#exer_se").is(':checked')) {
\t \t $('#exer_voting').fadeIn();
\t \t \t $('#label_s3').addClass("label_se_active");
\t \t \t
\t \t \t jQuery("textarea[class*=expand1-99]").TextAreaExpander();//initialize the text expand
}else{
\t \t $('#exer_voting').fadeOut();
\t \t \t $('#label_s3').removeClass("label_se_active"); \t \t
}
if ($("#reme_se").is(':checked')) {
\t \t $('#reme_voting').fadeIn();
\t \t \t $('#label_s4').addClass("label_se_active");
\t \t \t
\t \t \t jQuery("textarea[class*=expand1-99]").TextAreaExpander();//initialize the text expand
}else{
\t \t $('#reme_voting').fadeOut();
\t \t \t $('#label_s4').removeClass("label_se_active"); \t \t
}
if ($("#medi_se").is(':checked')) {
\t \t $('#medi_voting').fadeIn();
\t \t \t $('#label_s5').addClass("label_se_active");
\t \t \t
\t \t \t jQuery("textarea[class*=expand1-99]").TextAreaExpander();//initialize the text expand
}else{
\t \t $('#medi_voting').fadeOut();
\t \t \t $('#label_s5').removeClass("label_se_active"); \t \t
}
if ($("#others_se").is(':checked')) {
\t \t $('#others_voting').fadeIn();
\t \t \t $('#label_s6').addClass("label_se_active");
\t \t \t
\t \t \t jQuery("textarea[class*=expand1-99]").TextAreaExpander();//initialize the text expand
}else{
\t \t $('#others_voting').fadeOut();
\t \t \t $('#label_s6').removeClass("label_se_active"); \t \t
}
\t \t } // function menu_check
\t
\t
Помогло бы посмотреть структуру html, чтобы помочь настроить траверсы. – charlietfl