Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Odkrywanie <tr> poprzez class
Mateostin
post
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
Post #2





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
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
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 (IMG:style_emoticons/default/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ź (IMG:style_emoticons/default/exclamation.gif) !
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%)
-----


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
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 15.09.2025 - 13:11