Функция Jquery для каждого значения массива - PullRequest
0 голосов
/ 09 октября 2018

У меня есть одномерный массив (который представляет классы входного контейнера).Есть несколько входных контейнеров в виде чисел, содержащихся в массиве.

Я не хочу писать все функции для каждого значения, поэтому я использовал массив с Jquery.each.

Ноэтот код не работает, и я не понимаю, почему я не знаю точный синтаксис Jquery.each.

Извините за плохой английский.

Кто может мне помочь?

jQuery(document).ready(function($) {
    $('.selezioneprovincia input').bind('change', function() {
        var arr = [".AG",".AL",".AN",".AO",".AR",".AP",".AT",".AV",".BA",".BT",".BL",".BN",".BG",".BI",".BO",".BZ",".BS",".BR",".CA",".CL",".CB",".CI",".CE",".CT",".CZ",".CH",".CO",".CS",".CR",".KR",".CN",".EN",".FM",".FE",".FI",".FG",".FC",".FR",".GE",".GO",".GR",".IM",".IS",".SP",".AQ",".LT",".LE",".LC",".LI",".LO",".LU",".MC",".MN",".MS",".MT",".ME",".MI",".MO",".MB",".NA",".NO",".NU",".OT",".OR",".PD",".PA",".PR",".PV",".PG",".PU",".PE",".PC",".PI",".PT",".PN",".PZ",".PO",".RG",".RA",".RC",".RE",".RI",".RN",".RM",".RO",".SA",".VS",".SS",".SV",".SI",".SR",".SO",".TA",".TE",".TR",".TO",".OG",".TP",".TN",".TV",".TS",".UD",".VA",".VE",".VB",".VC",".VR",".VV",".VI",".VT"];
        jQuery.each( arr, function( i, val ) {
            if( $('.selezioneprovincia' + val + ' input').is(':checked') ){
                $('.selezionepv '+ val).show();  // checked
            } else {
                $('.selezionepv '+ val).hide();  // unchecked
                $('.selezionepv ' + val + ' input').prop("checked", false);
            }
        });
    });
});

часть HTML

    <div class="ipt_uif_column ipt_uif_column_full ipt_uif_conditional ipt_fsqm_container_p_checkbox selezioneprovincia" id="ipt_fsqm_form_11_pinfo_20">
<div class="ipt_uif_column_inner side_margin">
    <div class="ipt_uif_question ipt_uif_question_vertical">
        <div class="ipt_uif_question_label">
            <label class="ipt_uif_question_title ipt_uif_label" for="ipt_fsqm_form_11_pinfo_20">Seleziona la provincia<span class="ipt_uif_question_required">*</span></label>
            <div class="clear-both"></div>
        </div>
        <div class="ipt_uif_question_content">
            <div id="checkboxmaurizio" class="provincia Campania - BN ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__0" value="0">
                <label for="ipt_fsqm_form_11_pinfo_20_options__0" data-labelcon="">
                Campania - BN               </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Lazio - RM ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__1" value="1">
                <label for="ipt_fsqm_form_11_pinfo_20_options__1" data-labelcon="">
                Lazio - RM              </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Lombardia - NO ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__2" value="2">
                <label for="ipt_fsqm_form_11_pinfo_20_options__2" data-labelcon="">
                Lombardia - NO              </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Lombardia - BG ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__3" value="3">
                <label for="ipt_fsqm_form_11_pinfo_20_options__3" data-labelcon="">
                Lombardia - BG              </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Lombardia - BS ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__4" value="4">
                <label for="ipt_fsqm_form_11_pinfo_20_options__4" data-labelcon="">
                Lombardia - BS              </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Piemonte - AL ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__5" value="5">
                <label for="ipt_fsqm_form_11_pinfo_20_options__5" data-labelcon="">
                Piemonte - AL               </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Piemonte - TO ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__6" value="6">
                <label for="ipt_fsqm_form_11_pinfo_20_options__6" data-labelcon="">
                Piemonte - TO               </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Piemonte - VB ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__7" value="7">
                <label for="ipt_fsqm_form_11_pinfo_20_options__7" data-labelcon="">
                Piemonte - VB               </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Piemonte - VC ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__8" value="8">
                <label for="ipt_fsqm_form_11_pinfo_20_options__8" data-labelcon="">
                Piemonte - VC               </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Puglia - LE ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__9" value="9">
                <label for="ipt_fsqm_form_11_pinfo_20_options__9" data-labelcon="">
                Puglia - LE             </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Sicilia - CL ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__10" value="10">
                <label for="ipt_fsqm_form_11_pinfo_20_options__10" data-labelcon="">
                Sicilia - CL                </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Umbria - TR ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__11" value="11">
                <label for="ipt_fsqm_form_11_pinfo_20_options__11" data-labelcon="">
                Umbria - TR             </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Campania - SA ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__12" value="12">
                <label for="ipt_fsqm_form_11_pinfo_20_options__12" data-labelcon="">
                Campania - SA               </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Campania - AV ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__13" value="13">
                <label for="ipt_fsqm_form_11_pinfo_20_options__13" data-labelcon="">
                Campania - AV               </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Lazio - LT ipt_uif_label_column column_4" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][20][options][]" id="ipt_fsqm_form_11_pinfo_20_options__14" value="14">
                <label for="ipt_fsqm_form_11_pinfo_20_options__14" data-labelcon="">
                Lazio - LT              </label>
            </div>
            <div class="clear-both"></div>
            <div class="clear-both"></div>
        </div>
    </div>
    <div class="clear-both"></div>
</div>
     </div>
     <div class="ipt_uif_column ipt_uif_column_full ipt_uif_conditional ipt_fsqm_container_p_checkbox selezionepv" id="ipt_fsqm_form_11_pinfo_22">
<div class="ipt_uif_column_inner side_margin">
    <div class="ipt_uif_question ipt_uif_question_vertical">
        <div class="ipt_uif_question_label">
            <label class="ipt_uif_question_title ipt_uif_label" for="ipt_fsqm_form_11_pinfo_22">Seleziona uno o più punti vendita<span class="ipt_uif_question_required">*</span></label>
            <div class="clear-both"></div>
        </div>
        <div class="ipt_uif_question_content">
            <div id="checkboxmaurizio" class="provincia Centro commerciale in Str. alla Collina, a Valenza ( AL ) - Full-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__0" value="0">
                <label for="ipt_fsqm_form_11_pinfo_22_options__0" data-labelcon="">
                Centro commerciale in Str. alla Collina, a Valenza ( AL ) - Full-time               </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Centro commerciale in Via Achille Sclavo, ad Alessandria ( AL ) - Part-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__1" value="1">
                <label for="ipt_fsqm_form_11_pinfo_22_options__1" data-labelcon="">
                Centro commerciale in Via Achille Sclavo, ad Alessandria ( AL ) - Part-time             </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Negozio di giocattoli in Via Roma, a Telese ( BN ) - Full-time - Part-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__2" value="2">
                <label for="ipt_fsqm_form_11_pinfo_22_options__2" data-labelcon="">
                Negozio di giocattoli in Via Roma, a Telese ( BN ) - Full-time - Part-time              </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Centro commerciale Viale Monte Grappa, a Treviglio ( BG ) - Full-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__3" value="3">
                <label for="ipt_fsqm_form_11_pinfo_22_options__3" data-labelcon="">
                Centro commerciale Viale Monte Grappa, a Treviglio ( BG ) - Full-time               </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Libreria in Via Fratelli Galliari, a Treviglio ( BG ) - Full-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__4" value="4">
                <label for="ipt_fsqm_form_11_pinfo_22_options__4" data-labelcon="">
                Libreria in Via Fratelli Galliari, a Treviglio ( BG ) - Full-time               </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Centro commerciale in Via Arcangelo Tadini, a Brescia ( BS ) - Full-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__5" value="5">
                <label for="ipt_fsqm_form_11_pinfo_22_options__5" data-labelcon="">
                Centro commerciale in Via Arcangelo Tadini, a Brescia ( BS ) - Full-time                </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Libreria in Via John Fitzgerald Kennedy, a Caltanissetta ( CL ) - Part-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__7" value="7">
                <label for="ipt_fsqm_form_11_pinfo_22_options__7" data-labelcon="">
                Libreria in Via John Fitzgerald Kennedy, a Caltanissetta ( CL ) - Part-time             </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Negozio di giocattoli su Strada Provinciale Casarano - Maglie, a Casarano ( LE ) - Full-time - Part-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__8" value="8">
                <label for="ipt_fsqm_form_11_pinfo_22_options__8" data-labelcon="">
                Negozio di giocattoli su Strada Provinciale Casarano - Maglie, a Casarano ( LE ) - Full-time - Part-time                </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Centro commerciale in Via della Repubblica, a Borgomanero ( NO ) - Part-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__9" value="9">
                <label for="ipt_fsqm_form_11_pinfo_22_options__9" data-labelcon="">
                Centro commerciale in Via della Repubblica, a Borgomanero ( NO ) - Part-time                </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Libreria in Via Tiburtina, a Roma ( RM ) - Full-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__10" value="10">
                <label for="ipt_fsqm_form_11_pinfo_22_options__10" data-labelcon="">
                Libreria in Via Tiburtina, a Roma ( RM ) - Full-time                </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Libreria in Via Senofane, a Roma ( RM ) - Full-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__11" value="11">
                <label for="ipt_fsqm_form_11_pinfo_22_options__11" data-labelcon="">
                Libreria in Via Senofane, a Roma ( RM ) - Full-time             </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Libreria in Via del Governo Vecchio, a Roma ( RM ) - Full-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__12" value="12">
                <label for="ipt_fsqm_form_11_pinfo_22_options__12" data-labelcon="">
                Libreria in Via del Governo Vecchio, a Roma ( RM ) - Full-time              </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Libreria in Corso Cornelio Tacito, a Terni&nbsp; ( TR ) - Full-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__13" value="13">
                <label for="ipt_fsqm_form_11_pinfo_22_options__13" data-labelcon="">
                Libreria in Corso Cornelio Tacito, a Terni&nbsp; ( TR ) - Full-time             </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Centro commerciale in Via Robassomero, a Ciriè ( TO ) - Part-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__14" value="14">
                <label for="ipt_fsqm_form_11_pinfo_22_options__14" data-labelcon="">
                Centro commerciale in Via Robassomero, a Ciriè ( TO ) - Part-time               </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Centro commerciale in Via Camporotondo, a Cuorgnè ( TO ) - Part-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__15" value="15">
                <label for="ipt_fsqm_form_11_pinfo_22_options__15" data-labelcon="">
                Centro commerciale in Via Camporotondo, a Cuorgnè ( TO ) - Part-time                </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Centro commerciale in Corso Laghi, ad Avigliana ( TO ) - Part-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__16" value="16">
                <label for="ipt_fsqm_form_11_pinfo_22_options__16" data-labelcon="">
                Centro commerciale in Corso Laghi, ad Avigliana ( TO ) - Part-time              </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Centro commerciale in Piazza Aldo Moro, a Nichelino ( TO ) - Full-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__17" value="17">
                <label for="ipt_fsqm_form_11_pinfo_22_options__17" data-labelcon="">
                Centro commerciale in Piazza Aldo Moro, a Nichelino ( TO ) - Full-time              </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Centro commerciale in Via Palmiro Togliatti, a Crevoladossola ( VB ) - Part-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__18" value="18">
                <label for="ipt_fsqm_form_11_pinfo_22_options__18" data-labelcon="">
                Centro commerciale in Via Palmiro Togliatti, a Crevoladossola ( VB ) - Part-time                </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Centro commerciale in Via XXV Aprile, a Borgosesia ( VC ) - Part-time ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__19" value="19">
                <label for="ipt_fsqm_form_11_pinfo_22_options__19" data-labelcon="">
                Centro commerciale in Via XXV Aprile, a Borgosesia ( VC ) - Part-time               </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Negozio di elettronica in Via XXV Luglio, a Cava de' Tirreni ( SA ) ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__20" value="20">
                <label for="ipt_fsqm_form_11_pinfo_22_options__20" data-labelcon="">
                Negozio di elettronica in Via XXV Luglio, a Cava de' Tirreni ( SA )             </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Negozio di elettronica in Via Saltimatti, a Sarno ( SA ) ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__21" value="21">
                <label for="ipt_fsqm_form_11_pinfo_22_options__21" data-labelcon="">
                Negozio di elettronica in Via Saltimatti, a Sarno ( SA )                </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Negozio di elettronica in  Via Dante Alighieri, a Scafati ( SA ) ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__22" value="22">
                <label for="ipt_fsqm_form_11_pinfo_22_options__22" data-labelcon="">
                Negozio di elettronica in  Via Dante Alighieri, a Scafati ( SA )                </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Negozio di ellettronica in Via San Leonardo 52, a Salerno ( SA ) ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__23" value="23">
                <label for="ipt_fsqm_form_11_pinfo_22_options__23" data-labelcon="">
                Negozio di ellettronica in Via San Leonardo 52, a Salerno ( SA )                </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Negozio di elettronica in Via Nazionale Torrette,a Mercogliano ( AV ) ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__24" value="24">
                <label for="ipt_fsqm_form_11_pinfo_22_options__24" data-labelcon="">
                Negozio di elettronica in Via Nazionale Torrette,a Mercogliano ( AV )               </label>
            </div>
            <div id="checkboxmaurizio" class="provincia Negozio di elettronica in Via Vitruvio, a Formia ( LT ) ipt_uif_label_column column_2" style="display: none;">
                <input data-num="" type="checkbox" class="check_me validate[required] ipt_uif_checkbox  filled-in" name="ipt_fsqm_form_11[pinfo][22][options][]" id="ipt_fsqm_form_11_pinfo_22_options__25" value="25">
                <label for="ipt_fsqm_form_11_pinfo_22_options__25" data-labelcon="">
                Negozio di elettronica in Via Vitruvio, a Formia ( LT )             </label>
            </div>
            <div class="clear-both"></div>
            <div class="clear-both"></div>
        </div>
    </div>
    <div class="clear-both"></div>
</div>
     </div>

Ответы [ 3 ]

0 голосов
/ 09 октября 2018

вы пропускаете "" после .selezioneprovincia, должно быть:

jQuery(document).ready(function($) {
$('.selezioneprovincia input').bind('change', function() {
    var arr = .....;
    jQuery.each( arr, function( i, val ) {
        if( $('.selezioneprovincia ' + val + ' input').is(':checked') ){
            ....
    });
});
});
0 голосов
/ 09 октября 2018

В селекторе jQuery не хватает места:

if( $('.selezioneprovincia ' + val + ' input').is(':checked') )

И я переместил массив из обработчика изменений.

Полный код js:

$(function() {

var arr = [".AG",".AL",".AN",".AO",".AR",".AP",".AT",".AV",".BA",".BT",".BL",".BN",".BG",".BI",".BO",".BZ",".BS",".BR",".CA",".CL",".CB",".CI",".CE",".CT",".CZ",".CH",".CO",".CS",".CR",".KR",".CN",".EN",".FM",".FE",".FI",".FG",".FC",".FR",".GE",".GO",".GR",".IM",".IS",".SP",".AQ",".LT",".LE",".LC",".LI",".LO",".LU",".MC",".MN",".MS",".MT",".ME",".MI",".MO",".MB",".NA",".NO",".NU",".OT",".OR",".PD",".PA",".PR",".PV",".PG",".PU",".PE",".PC",".PI",".PT",".PN",".PZ",".PO",".RG",".RA",".RC",".RE",".RI",".RN",".RM",".RO",".SA",".VS",".SS",".SV",".SI",".SR",".SO",".TA",".TE",".TR",".TO",".OG",".TP",".TN",".TV",".TS",".UD",".VA",".VE",".VB",".VC",".VR",".VV",".VI",".VT"];


$('.selezioneprovincia input').bind('change', function() {        

    $.each( arr, function( i, val ) {
        if( $('.selezioneprovincia ' + val + ' input').is(':checked') ){
            $('.selezionepv '+ val).show();  // checked
        } else {
            $('.selezionepv '+ val).hide();  // unchecked
            $('.selezionepv ' + val + ' input').prop("checked", false);
        }
    });

   });
 });

https://jsfiddle.net/xpvt214o/873523/

Рабочий пример.Он начинается со всех показанных входов.

0 голосов
/ 09 октября 2018

Вы можете использовать простой цикл for:

$('.selezioneprovincia input').on('change', function() {
    var arr = [...];
    for (var i in arr) {
        var val = arr[i];
        var elem = $('.selezionepv '+ val);
        if ($(this).is(':checked')) {
           elem.show();
        } else {
           elem.hide().find('input').prop('checked', false);
        }
    }
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...