Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [HTML][JavaScript]jQuery checkboxy wyróżnienie zaznaczonych
noche
post
Post #1





Grupa: Zarejestrowani
Postów: 46
Pomógł: 0
Dołączył: 20.02.2015

Ostrzeżenie: (0%)
-----


Kod
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>

    $(document).ready(function(){
        var $labelCheck = $('.checkbox3');
        $labelCheck.on("change", function() {
                $labelCheck.each( function( index, element  ) {
            
                                    if( $(this).is(':checked')) {
                                        $(this).css({"background-color": "red" });  
                                    } else {
                                        $(this).css({"background-color": "white" });  
                                    }
                                      //$(element).removeClass( "gp-red" ).addClass( "gp-white" );
                                      //$(this).css({"background-color": "red" });
                                    //};
        });
        });
        
        var $box3 = $('.box3');
        $box3.on("change", function() {
                    if ($('.box1').is(':checked')) {
                      $(this).css({"background-color": "red" });  
                    } else {
                      $(this).css({"background-color": "white" });  
                    }
        });

    });

</script>

<form action="#">
    <label class="checkbox3 gp-red"><input class="checkbox1" type="checkbox" name="vehicle1" value="Bike1" checked='checked' > bike 1 <br></label>
    <label class="checkbox3 gp-red"><input class="checkbox1" type="checkbox" name="vehicle2" value="Bike2" checked='checked' > bike 2 <br></label>
    <label class="checkbox3 gp-red"><input class="checkbox1" type="checkbox" name="vehicle3" value="Bike3" checked='checked' > bike 3 <br></label>
  <input type="submit" value="Submit">
</form>
<form action="#">
    <label class="box3 gp-red"><input class="box1" type="checkbox" name="vehicle1" value="Bike1" checked='checked' > bike 1 <br></label>
  <input type="submit" value="Submit">
</form>


chce na całej stronie wyróżnić checkbox'y które zostały zaznaczone i zmienić im tło
skrypt z zmienna $box3 działa ale nie mogę tego zrobić dla wielu checkbox'ów
jak widać to moje początki z jQ (IMG:style_emoticons/default/smile.gif)
jak w JS mogę podglądnąć obiekt ?
proszę o podpowiedz jak to ugryść bo brakło mi już pomysłów

Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 01:01