Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript] Buttony
Chelo
post 11.10.2009, 22:14:47
Post #1





Grupa: Zarejestrowani
Postów: 178
Pomógł: 8
Dołączył: 19.03.2007

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


Witam wszystkich. Mam problem z buttonami otóż mam taki kod:

  1. <script type="text/javascript">
  2. window.onload = Laduj;
  3. function Pokaz()
  4. {
  5. var div = document.getElementById('wiecej');
  6. var odnosnik = document.getElementById('link');
  7.  
  8. var view = div.style.display;
  9.  
  10. if (view == "block")
  11. {
  12.  
  13. odnosnik.innerHTML = "<input type=\"button\" value=\"nid\">";
  14. div.style.display = "none";
  15. }
  16.  
  17. if (view == "none")
  18. {
  19. odnosnik.innerHTML = "<input type=\"button\" value=\"nid\">";
  20. div.style.display = "block";
  21. }
  22.  
  23. }
  24.  
  25. function Laduj()
  26. {
  27. var odnosnik = document.getElementById('link');
  28. odnosnik.onclick = Pokaz;
  29. }
  30.  
  31.  
  32. </script>

  1. <div><a href="#" id="link"><input type="button" value="nid"></a></div>
  2. <div id="wiecej" style="display: none;">NFO:<br><textarea rows="5" cols="30" name="cqqwd"></textarea> </div>


Ten kod pokazuje button, po naciśnięciu się otwiera <textarea> ... a po kliknięciu drugi raz chowa się ...
Wszystko działa, jednak jak zastosować to samo przy drugim przycisku?questionmark.gif

Proszę o pomoc

Go to the top of the page
+Quote Post
glh
post 12.10.2009, 10:28:47
Post #2





Grupa: Zarejestrowani
Postów: 97
Pomógł: 20
Dołączył: 18.12.2007
Skąd: Poznań

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


Jakim drugim przycisku?
W kodzie masz tylko jeden.


--------------------
Go to the top of the page
+Quote Post
siutek
post 12.10.2009, 11:04:46
Post #3





Grupa: Zarejestrowani
Postów: 173
Pomógł: 1
Dołączył: 26.10.2005
Skąd: Toruń

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


po pierwsze wydaje mi sie ze bardziej elegancko bedzie jesli na buttonie zastosujesz onClick zamiast <a>,
po drugie:

  1. <script language='JavaScript'>
  2. function pokaz(pole){
  3. if (document.getElementById(pole).style.display == "none"){
  4. document.getElementById(pole).style.display = "";
  5. } else {
  6. document.getElementById(pole).style.display = "none";
  7. }
  8. }
  9. <div>
  10. <input type="button" value="nid" onClick="pokaz('txtarea1')">
  11. <input type="button" value="nid" onClick="pokaz('txtarea2')">
  12. </div>
  13.  
  14. <div id="txtarea1" style="display: none;">
  15. NFO:<br>
  16. <textarea rows="5" cols="30" name="cqqwd"></textarea>
  17. </div>
  18.  
  19. <div id="txtarea2" style="display: none;">
  20. NFO:<br>
  21. <textarea rows="5" cols="30" name="cqqwd2"></textarea>
  22. </div>

kluczem (doslownie) jest odwolanie sie do konkretnego diva poprzez jego ID

moze byc? czy nie o to Ci chodzilo??

Ten post edytował siutek 12.10.2009, 11:07:16
Go to the top of the page
+Quote Post

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: 26.04.2024 - 02:42