Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [HTML][JavaScript] Przycisk On/Off
lolarz
post
Post #1





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 5.07.2013

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


Kod
function func1 () {
    var box1 = document.getElementById('box1');
    var classes = box1.className.split(' ');
    var index = classes.indexOf('active');
    if (index == -1) {
        classes.push('active');
    } else {
        classes.splice(index, 1);
    }
    box1.className = classes.join(' ');


Czy ten skrypt da się przerobić tak, aby gdy włącza się klasa .active jednocześnie wartość w: <input type="hidden" id="check1" value="0"> zmieniała się na 1, a po kliknięciu jeszcze raz, czyli po wyłączeniu klasy .active wartość zmieniała się z powrotem na 0?

Ten post edytował lolarz 7.10.2016, 17:41:53
Go to the top of the page
+Quote Post
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




A jaki problem zrobic
document.getElementById('check1').value=0
?
Go to the top of the page
+Quote Post
lolarz
post
Post #3





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 5.07.2013

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


Już coś takiego próbowałem zrobić i właśnie nie działało, chyba że coś źle robię https://jsfiddle.net/4012Lpfx/3/

Ten post edytował lolarz 7.10.2016, 18:04:39
Go to the top of the page
+Quote Post
trueblue
post
Post #4





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Działa.

P.S. Zmień w JSFiddle load type na: no wrap.
Go to the top of the page
+Quote Post
lolarz
post
Post #5





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 5.07.2013

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


Dzięki wielkie, działa (IMG:style_emoticons/default/biggrin.gif)
Go to the top of the page
+Quote Post

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: 23.08.2025 - 05:08