Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Odkrywanie <tr> poprzez class
Mateostin
post 1.01.2018, 18:41:13
Post #1





Grupa: Zarejestrowani
Postów: 68
Pomógł: 0
Dołączył: 23.03.2016

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


Witam,

Mam napisany taki kodzik

  1. function showComments($counterComments) {
  2. var x = document.getElementsByClassName($counterComments)[0];
  3. if (x.style.display === "none") {
  4. x.style.display = "";
  5. } else {
  6. x.style.display = "none";
  7. }
  8. }


Nie potrafie przerobić tego tak aby skrypt chował i odkrywał wszystkie tr ktore są w petli, w tym przypadku działa tylko dla pierwszego wygenerowanego tr,
czy jest na to jakas rada?
Go to the top of the page
+Quote Post
trueblue
post 1.01.2018, 18:42:59
Post #2





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

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


https://developer.mozilla.org/pl/docs/Web/API/NodeList


--------------------
Go to the top of the page
+Quote Post
Mateostin
post 1.01.2018, 18:47:02
Post #3





Grupa: Zarejestrowani
Postów: 68
Pomógł: 0
Dołączył: 23.03.2016

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


Ehhhhh, napisałem posta i nagle dostałem oswiecenia smile.gif

zrobiłem tak, ze zliczylem sobie elementy tr i w petli odwoluje do tablicy:

  1. function showComments($counterComments, $countElement) {
  2. for (i = 0; i < $countElement; i++) {
  3.  
  4. var x = document.getElementsByClassName($counterComments)[i];
  5. if (x.style.display === "none") {
  6. x.style.display = "";
  7. } else {
  8. x.style.display = "none";
  9. }}
  10. }


takze to rozwiazanie mi działa, Pozdrawiam i dziekuje za błyskawiczną odpowiedź exclamation.gif!
Go to the top of the page
+Quote Post
trueblue
post 1.01.2018, 18:52:12
Post #4





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

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


Zliczać elementów nie musisz, tzn. nie musisz liczby przekazywać jako argument funkcji.
Liczba elementów będzie właściwością length listy węzłów, które pobierzesz za pomocą getElementsByClassName, którą notabene powinieneś wyprowadzić poza pętlę.


--------------------
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 19.04.2024 - 02:44