2016-12-14 4 views
-4

hier zu verkürzen ist mein Code, der hereBenötigen Sie Hilfe dieses jQuery-Funktionen

Brauchen Sie Hilfe bei etwas wie dies in tut gut funktioniert:

$('.date-container input').click(function() { 
    var j; 
    for (j = 1; j <= 4; j++) { 

     $('.day' + (j + 1) + '-times').hide('slow'); 

     $(this).$('.day' + (j + 1) + '-times').show('slow'); 
    } 
}); 
+0

Ihr Code scheint nicht zu Radios von Kontrollkästchen wechseln wollen w Ork so gut - es zeigt mir immer noch 'Tag 2' Artikel, wenn ich dieses Kästchen deaktivieren –

+1

'j! == i' ......... ??? – Jai

+0

Probieren Sie: '[... Array (4)]. ForEach ((x, i) => {/ * Code innerhalb Ihrer For-Schleife * /});' –

Antwort

3

Dies ist eine kürzere Version Ihrer Geige JS-Code:

$(document).ready(function() { 
    // When document is ready, we bind the click event on every 'input' in the '.date-container' div 
    $('.date-container input').click(function(){ 
    // When a click event is triggered on one of those 'input', we hide 
    // all the 'div' that are in the '#checkboxradio' element 
    $('#checkboxradio > div').hide('slow'); 
    // Using the 'id' attribute of the input that triggered the clicked 
    // event (e.g. "day1"), we build a jQuery selector that'll be used 
    // to select the proper checkboxes time container 
    // (e.g. "." + "day1" + "-times" = ".day1-times") 
    // Then we stop all animations on that element (prevent hiding if 
    // it's the element we actually want to display) 
    // and trigger a show animation on that same element 
    $('.' + $(this).prop('id') + '-times').stop().show('slow'); 
    }); 
}); 

Sie wahrscheinlich

+0

das funktioniert perfekt für meinen Fall. Ich brauche mehrere Daten gleichzeitig ausgewählt, deshalb hatte ich Kontrollkästchen über Radio verwendet. Vielen Dank und allen anderen für Ihre Zeit. – M1988

+1

Ich habe Kommentare zu meiner Antwort hinzugefügt :). Prost ! – H4ris