Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JS] Zablokowanie kilku inputów
Hectic
post
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 (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Hectic
post
Post #2





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 (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Może dało się to zrobić dużo prościej, ale w JS jestem początkujący (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)
Dzięki (IMG:http://forum.php.pl/style_emoticons/default/Rkingsmiley.png)
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: 26.12.2025 - 08:08