Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript]Optymalizacja kodu.
Forum PHP.pl > Forum > Przedszkole
Wicepsik
Jest to mój pierwszy kod javascript. Czy da się jakoś skrócić ten kod?

Działanie kodu można zobaczyć http://skust.info/?menu=czary76 zaznaczając i odznaczając checkboxy.

  1. <?php
  2. <script type="text/javascript">
  3. function check(box)
  4. {
  5.  
  6. if (document.formx.turban.checked == true)
  7. {
  8.  document.formx.sapphire.disabled = true;
  9.  document.formx.cursedclow.disabled = true;
  10.    
  11. } else {
  12.  
  13.  document.formx.sapphire.disabled = false;
  14.  document.formx.cursedclow.disabled = false;    
  15.    
  16.            if (document.formx.sapphire.checked == true)
  17.            {
  18.              document.formx.robe.disabled = true;
  19.              document.formx.turban.disabled = true;
  20.              document.formx.cursedclow.disabled = true;
  21.            } else {
  22.              document.formx.robe.disabled = false;
  23.              document.formx.turban.disabled = false;
  24.              document.formx.cursedclow.disabled = false;    
  25.                
  26. if ((document.formx.robe.checked == true) && (document.formx.cursedclow.checked == true))
  27.    {
  28.  document.formx.turban.disabled = true;
  29.  document.formx.sapphire.disabled = true;
  30.    
  31. } else {
  32.  document.formx.turban.disabled = false;
  33.  document.formx.sapphire.disabled = false;
  34.    
  35.              if (document.formx.robe.checked == true)
  36.              {
  37.              document.formx.sapphire.disabled = true;
  38.              } else {
  39.              document.formx.sapphire.disabled = false;
  40.  
  41.                
  42.              if (document.formx.cursedclow.checked == true)
  43.              {
  44.              document.formx.sapphire.disabled = true;
  45.              document.formx.turban.disabled = true;
  46.              } else {
  47.              document.formx.sapphire.disabled = false;
  48.              document.formx.turban.disabled = false;
  49.                
  50.  
  51.        }        
  52.      }
  53.    }
  54.  }
  55. }
  56.  
  57. return true;
  58.  
  59. }
  60. </script>
  61. ?>
Darti
Nie wiem, może zadziała - z palca pisane smile.gif

Kod
var robe = new Array("sapphire");
var turban = new Array("sapphire", "cursedclow");
// var inne do wpisania

function check(box){

podrzedne = eval(box.id);
if(box.checked == true){
for (n = 0; n < podrzedne.lenght; n++){
    do_wylaczenia = document.getElementById(podrzedne[n]);
    do_wylaczenia.checked = false;
    do_wylaczenia.disabled = true;
}
} else {
for (n = 0; n < podrzedne.lenght; n++){
    do_wylaczenia = document.getElementById(podrzedne[n]);
    do_wylaczenia.disabled = false;
}
}
}


}
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.