![]() |
![]() ![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 256 Pomógł: 7 Dołączył: 1.01.2005 Ostrzeżenie: (0%) ![]() ![]() |
Mam 5 inputów o id='g5'. Czy da się je wszystkie zablokować naraz? Zrobiłem coś takiego
Kod function acc(group) { val = document.getElementById(group).disabled; if(val == true) { document.getElementById(group).disabled=false; } else { document.getElementById(group).disabled=true; } } Ale po wywołaniu funkcji Cytat acc("g5") blokuje się tylko pierwszy input ![]() -------------------- Nie proś o to, idź i sam to zdobądź.
Zrób to, a osiągniesz sukces. |
|
|
![]()
Post
#2
|
|
Grupa: Zarejestrowani Postów: 10 Pomógł: 0 Dołączył: 7.08.2006 Ostrzeżenie: (0%) ![]() ![]() |
Z tego co wiem id jest identyfikatorem danego elementu. Takze w dokumencie kazdy element musi miec inne id. Dlatego funkcja getElementById pobiera pierwszy który znajdzie.
|
|
|
![]()
Post
#3
|
|
Grupa: Zarejestrowani Postów: 256 Pomógł: 7 Dołączył: 1.01.2005 Ostrzeżenie: (0%) ![]() ![]() |
Bardziej chodziło mi o to czy ktoś mam pomysł na rozwiązanie tego problemu w inny sposób
![]() -------------------- Nie proś o to, idź i sam to zdobądź.
Zrób to, a osiągniesz sukces. |
|
|
![]()
Post
#4
|
|
Grupa: Zarejestrowani Postów: 130 Pomógł: 1 Dołączył: 29.06.2007 Ostrzeżenie: (0%) ![]() ![]() |
Kod function acc(it) { val = it.disabled; if(val == true) { it.disabled=false; } else { it.disabled=true; } } i przekazuj przez funkcje referencje do 'this' (mozna wywalic id), jeśli nie możesz operować na 'this' bo odwolujesz sie do innego węzła to możesz zrobić klase i odwolywac sie przez getElementsByClassName zamiast getElementById Ten post edytował flv 30.06.2007, 18:06:00 |
|
|
![]()
Post
#5
|
|
Grupa: Zarejestrowani Postów: 256 Pomógł: 7 Dołączył: 1.01.2005 Ostrzeżenie: (0%) ![]() ![]() |
Idąc za Twoją radą zrobiłem coś takiego
Kod function getElementsByClassName(cn){ var arr = new Array(); var els = document.getElementsByTagName("*"); var exp= new RegExp("^(.* )?"+cn+"( .*)?$", "g"); for (var i = 0; i < els.length; i++ ){ if (exp.test(els[i].className)){ arr.push(els[i]); } } return arr; } Kod function acc(group) { val = getElementsByClassName(group); all = val.length; for($a = 0; $a < all; $a++) { inpu = val[$a].name; disable = document.getElementById(inpu).disabled; if(disable == true) { document.getElementById(inpu).disabled=false; } else { document.getElementById(inpu).disabled=true; } } } Nawet działa ![]() ![]() Dzięki ![]() -------------------- Nie proś o to, idź i sam to zdobądź.
Zrób to, a osiągniesz sukces. |
|
|
![]()
Post
#6
|
|
Grupa: Zarejestrowani Postów: 229 Pomógł: 0 Dołączył: 29.05.2007 Ostrzeżenie: (0%) ![]() ![]() |
albo
i teraz przekazujesz jako parametr listę id, kolejne id oddzielone przecinkami np |
|
|
![]() ![]() |
![]() |
Aktualny czas: 19.08.2025 - 16:19 |