Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Polecenie które zwróci wszystkie elementy wskazanego id, document.getElementById('x') zwraca tylko jeden element.
twojastara
post
Post #1





Grupa: Zarejestrowani
Postów: 124
Pomógł: 0
Dołączył: 25.11.2014

Ostrzeżenie: (10%)
X----


Chciałbym znać polecenie, które zwróci mi wszystkie elementy o wskazanym id.

polecenie document.getElementsByTagName('input') zwraca

  1. <input type="number" id="inputISBN" name="1111" value="2" >
  2. <input type="number" id="inputISBN" name="2222" value="2" >
  3. <input type="submit" value="Zatwierdź zmiany">



polecenie document.getElementById('inputISBN') zwraca tylko jedna linię, pierwszą.
  1. <input type="number" id="inputISBN" name="1111" value="2" >


Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
twojastara
post
Post #2





Grupa: Zarejestrowani
Postów: 124
Pomógł: 0
Dołączył: 25.11.2014

Ostrzeżenie: (10%)
X----


no tak, klasa.

a jak zrobić pętle w JavaScript, która wypełni mi tablicę, gdzie klucz=>wartość będzie elementy[i].getAttribute('name')=>elementy[i].getAttribute('value')

niezdarnie mniej więcej coś takiego:

  1. var elementy = document.getElementsByClassName('inputISBN')
  2. function (){
  3. var o = [];
  4. for (var i = 0; i < elementy.length; i++){
  5. o[elementy[i].getAttribute('name')] = o[elementy[i].getAttribute('value')]
  6. }
  7. }



coś co w php byłoby tablicą asocjacyjną

  1. for (i=0; i<3; i++){
  2.  
  3. $tablica[elementy[i].getAttribute('name')]=elementy[i].getAttribute('value');
  4. }


Ten post edytował twojastara 25.04.2015, 20:22:13
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: 7.10.2025 - 18:11