Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [CSS][JavaScript]style.block,none
neo1986kk
post
Post #1





Grupa: Zarejestrowani
Postów: 561
Pomógł: 3
Dołączył: 2.02.2009

Ostrzeżenie: (0%)
-----


  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2.  
  3. <html>
  4. <head>
  5. <title>Untitled</title>
  6.  
  7. <style type="text/css">
  8. <!--
  9. #dropper { display: none; }
  10. -->
  11. </style>
  12.  
  13. <script language="JavaScript" type="text/javascript">
  14. <!--
  15. function toggleDiv(element){
  16. if(document.getElementById(element).style.display = 'none')
  17. {
  18. document.getElementById(element).style.display = 'block';
  19. }
  20. else if(document.getElementById(element).style.display = 'block')
  21. {
  22. document.getElementById(element).style.display = 'none';
  23. }
  24. }
  25. //-->
  26. </script>
  27.  
  28. </head>
  29. <body>
  30. <div onClick="toggleDiv('dropper')">Main</div>
  31.  
  32. <div id="dropper">
  33. <ul>
  34. <li>1</li>
  35. <li>2</li>
  36. </ul>
  37. </div>
  38. </body>
  39. </html>


Dlaczego po ponownym naciśnięciu nie chowa elementu <div id="dropper">??
Kod wydaje sie poprawny, konsola nie wyświetla błedów, sprawdzane na FF
Go to the top of the page
+Quote Post
bełdzio
post
Post #2





Grupa: Zarejestrowani
Postów: 690
Pomógł: 81
Dołączył: 6.04.2005
Skąd: Szczecin

Ostrzeżenie: (0%)
-----


w ifach zamiast = daj ==

Ten post edytował bełdzio 24.01.2010, 19:13:51
Go to the top of the page
+Quote Post
Burned
post
Post #3





Grupa: Zarejestrowani
Postów: 67
Pomógł: 8
Dołączył: 19.05.2004
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Jakiś podobny problem kiedyś miałem.
Poekserymentowałem trochę i działające rozwiązanie wyglądało mniej więcej tak:
  1. <script language="JavaScript" type="text/javascript">
  2. <!--
  3. function toggleDiv(element){
  4. var myElement = document.getElementById(element);
  5. if(myElement.style.display != 'block')
  6. {
  7. myElement.style.display = 'block';
  8. }
  9. else
  10. {
  11. myElement.style.display = 'none';
  12. }
  13. }
  14. //-->
  15. <a href="#" onClick="toggleDiv('dropper');return false;">Main</a>
  16.  
  17. <div id="dropper" style="display:none;">
  18. <ul>
  19. <li>1</li>
  20. <li>2</li>
  21. </ul>
  22. </div>

Nie zagłębiałem się dlaczego tak działa, a inaczej nie za bardzo chce.

EDIT:
bełdzio zauważył faktycznie ważny błąd, przez który nie miało prawa działać.

Ten post edytował Burned 24.01.2010, 19:14:38
Go to the top of the page
+Quote Post
neo1986kk
post
Post #4





Grupa: Zarejestrowani
Postów: 561
Pomógł: 3
Dołączył: 2.02.2009

Ostrzeżenie: (0%)
-----


Tak moim tokiem myslenia to wydaje mi się, że JS nie rozpoznaje style = none dlatego kod (if myelement !='block') działa.
Poprostu mówi on, że nie jeśli jest NONE
tylko jeśli jest inny niż BLOCK

Tak mi się wydaje...

Ten post edytował neo1986kk 24.01.2010, 19:35:57
Go to the top of the page
+Quote Post

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: 4.10.2025 - 17:57