Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [js] Ocena poprawności funkcji
-Wieviór-
post 26.02.2008, 19:43:22
Post #1





Goście







Generalnie napisałem sobie funkcję zmieniania zawartości div'a, tzn. nie zamieniania zawartości, a przełączenia divów. Jestem zupełnie początkujący w js, i napisanie tego mi trochę zajęło, ale się czegoś nauczyłem ;] Zastanawiam się tylko, czy ta funkcja jest w miarę poprawnie napisana? I też, do czego służy to "return false;" w onclick=""?

  1. <script type="text/javascript"><!--
  2. function changeBox(name) {
  3. switch (name)
  4. {
  5. case 'forum':
  6. document.getElementById('forum').style.display='';
  7. document.getElementById('sonda').style.display='none';
  8. document.getElementById('foto').style.display='none';
  9. break
  10. case 'sonda':
  11. document.getElementById('forum').style.display='none';
  12. document.getElementById('sonda').style.display='';
  13. document.getElementById('foto').style.display='none';
  14. break
  15. case 'foto':
  16. document.getElementById('forum').style.display='none';
  17. document.getElementById('sonda').style.display='none';
  18. document.getElementById('foto').style.display='';
  19. break
  20. }
  21. }
  22. //-->
  23. </head>
  24. <a href="#" onclick="changeBox('forum'); return false;">a</a><br>
  25. <a href="#" onclick="changeBox('sonda'); return false;">b</a><br>
  26. <a href="#" onclick="changeBox('foto'); return false;">c</a><br>
  27.  
  28. <div id="forum" style="display: none;">aaaaaaaa</div>
  29. <div id="sonda" style="display: none;">bbbaabbbbb</div>
  30. <div id="foto" style="display: none;">cccccccc</div>
  31. </body>
  32. </html>


Pozdrawiam ;]
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 7.07.2025 - 03:03