Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript][HTML]Pomoc przy funkcji JS
Raven1122
post
Post #1





Grupa: Zarejestrowani
Postów: 369
Pomógł: 2
Dołączył: 1.11.2010

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


Witam, napisalem taki kodzik:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <script type="text/javascript">
  4. function togglediv(id){
  5. var divstatus = document.getElementById(id);
  6. if(divstatus.style.display == 'block')
  7. divstatus.style.display = 'none';
  8. else
  9. divstatus.style.display = 'block';
  10. }
  11. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  12. <meta http-equiv="Content-Language" content="pl" />
  13. <meta name="Robots" content="ALL" />
  14. <meta name="keywords" content="">
  15. <meta name="description" content="" />
  16. </head>
  17. <a onClick="togglediv('foo')">Naglowek 1</a>
  18. <div id="foo" style="display:block;">Tresc naglowka 1</div>
  19. <br /><br /><br />
  20. <a onClick="togglediv('foo2')">Naglowek 2</a>
  21. <div id="foo2" style="display:none;">Tresc naglowka 2</div>
  22. </body>
  23. </html>


I teraz potrzebuje zrobic tak, aby przy otworzeniu naglowka 2 automatycznie zamykal sie naglowek 1, jak to zrobic?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
b4rt3kk
post
Post #2





Grupa: Zarejestrowani
Postów: 1 933
Pomógł: 460
Dołączył: 2.04.2010
Skąd: Lublin

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


Dobra, inaczej, to musi działać (IMG:style_emoticons/default/smile.gif)

  1. <div>
  2. <a href="#">Naglowek 1</a>
  3. <div class="klasa1" style="display:block;">Tresc naglowka 1</div>
  4. </div>
  5. <div>
  6. <a href="#">Naglowek 2</a>
  7. <div class="klasa1" style="display:none;">Tresc naglowka 2</div>
  8. </div>


Skrypt:

  1. <script type="text/javascript">
  2. $(
  3. $('a').click(function(){
  4. $('.klasa1').attr('style', 'display: none;');
  5. $(this).closest('div').children('.klasa1').show('fast');
  6. };);
  7. );
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: 12.10.2025 - 07:55