Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> przelacznik z dwoma przyciskami
wojtektorr
post
Post #1





Grupa: Zarejestrowani
Postów: 27
Pomógł: 0
Dołączył: 19.02.2011

Ostrzeżenie: (10%)
X----


Witam serdecznie, mam na stronie dwa divy i dwa przyciski, divy są ukryte. Klikając na button "in" pokazuje się div "wew" i akutomatycznie przycisk staj sie nieaktywny, w tym momencie mogę wybrać drógi przycisk "out" i po jego kliknięciu pokazuje sie div "zew" i z kolei ten przyciks staje sie nie aktywny a aktywnym staje się przycisk "in" i tak w kółko. Nie mogęzrobić tego przełączania miedzy nieaktywnymi przyciskami. Myślę z z kodu więcej zrozumiecie.
  1. <div id="change">
  2. <table align="left">
  3. <tr align="center">
  4. <td><input type="button" class="in" value="Zgłoszenie wewnętrzne" onclick="java script:change(this);"/></td>
  5. <td><input type="button" class="out" value="Zgłoszenie zewnętrzne" onclick="java script:change(this);"/></td>
  6. </tr>
  7. </table>
  8. </div>
  9.  
  10. <script type="text/javascript">
  11.  
  12. function change(item){
  13. if(item.className == "in") {
  14. item.disabled = "true";
  15. document.getElementById("zew").style.display = "none";
  16. document.getElementById("wew").style.display = "block";
  17. }
  18. else {
  19. item.disabled = "true";
  20. document.getElementById("zew").style.display = "block";
  21. document.getElementById("wew").style.display = "none";
  22.  
  23. document.getElementByClassName("in").setAttribute("disabled", "false");
  24. }
  25. }


Ta ostatnia linia kodu (document.getElementByClassName("in").setAttribute("disabled", "false")wink.gif nie chce zadziałać, dlaczego?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 9)
werdan
post
Post #2





Grupa: Zarejestrowani
Postów: 354
Pomógł: 100
Dołączył: 14.11.2013
Skąd: Płock

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


Sprobuj:

document.getElementByClassName("in").removeAttribute("disabled");
Go to the top of the page
+Quote Post
Turson
post
Post #3





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Cytat(wojtektorr @ 7.02.2014, 16:40:55 ) *
Ta ostatnia linia kodu (document.getElementByClassName("in").setAttribute("disabled", "false")wink.gif nie chce zadziałać, dlaczego?

Sprawdź czy to coś zmienia
  1. <input type="submit" disabled=true>
  2. <input type="submit" disabled=false>

potem wyciągnij wniosek wink.gif
Go to the top of the page
+Quote Post
wojtektorr
post
Post #4





Grupa: Zarejestrowani
Postów: 27
Pomógł: 0
Dołączył: 19.02.2011

Ostrzeżenie: (10%)
X----


Hmm efekt taki sam czy disabled=true czy disabled=false, ale jak usunac ten atrybut po uprzednim jego ustawieniu nadal nie wiem :/
Go to the top of the page
+Quote Post
Kshyhoo
post
Post #5





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




O to Ci chodzi?
[JAVASCRIPT] pobierz, plaintext
  1. function disable_enable(_this) {
  2. if (_this == 'in') {
  3. document.test.in.disabled=true;
  4. document.test.out.disabled=false;
  5. } else {
  6. document.test.in.disabled=false;
  7. document.test.out.disabled=true;
  8. }
  9. }
[JAVASCRIPT] pobierz, plaintext

  1. <form name="test" >
  2. <input type="button" id="in" value="Zgłoszenie wewnętrzne" name="b1" onclick="disable_enable('in');" >
  3. <input type="button" id="out" value="Zgłoszenie zewnętrzne" name="b2" onclick="disable_enable('out');">
  4. </form>


--------------------
Go to the top of the page
+Quote Post
wojtektorr
post
Post #6





Grupa: Zarejestrowani
Postów: 27
Pomógł: 0
Dołączył: 19.02.2011

Ostrzeżenie: (10%)
X----


Dokładnie o to, dzięki! Jeszcze jedno, czy muszę te buttony umieszczać w jakimś formularzu mogę sie do nich w funkcji odwołać jakoś z pominięciem document....out.disabled=false;

Ten post edytował wojtektorr 8.02.2014, 10:24:25
Go to the top of the page
+Quote Post
Kshyhoo
post
Post #7





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




Bez FORM nie będzie chciało włączać DIV.
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//en">
  2. <title>Demo</title>
  3.  
  4. <meta http-equiv="Content-Type" content="text/html;" charset="utf-8">
  5. <meta http-equiv="Content-Language" content="pl">
  6. <style type="text/css">
  7. #wew {
  8. position: relative;
  9. width: 500px;
  10. height: 300px;
  11. background-color: #f00;
  12. margin: 0 auto;
  13. display: none;
  14. }
  15. #zew {
  16. position: relative;
  17. width: 500px;
  18. height: 300px;
  19. background-color: #33f;
  20. margin: 0 auto;
  21. display: none;
  22. }
  23. input[disabled] {
  24. color: red;
  25. text-decoration: none;
  26. }
  27.  
  28. <script language="JavaScript">
  29. function disable_enable(_this) {
  30. if (_this == 'in') {
  31. document.test.in.disabled=true;
  32. document.test.out.disabled=false;
  33. document.getElementById("zew").style.display = "none";
  34. document.getElementById("wew").style.display = "block";
  35. } else {
  36. document.test.in.disabled=false;
  37. document.test.out.disabled=true;
  38. document.getElementById("zew").style.display = "block";
  39. document.getElementById("wew").style.display = "none";
  40. }
  41. }
  42. </head>
  43.  
  44. <div id="change">
  45. <table align="left">
  46. <tr align="center">
  47. <form name="test" >
  48. <td>
  49. <input type="button" id="in" value="Zgłoszenie wewnętrzne" name="b1" onclick="disable_enable('in');" >
  50. </td>
  51. <td>
  52. <input type="button" id="out" value="Zgłoszenie zewnętrzne" name="b2" onclick="disable_enable('out');">
  53. </td>
  54. </form>
  55. </tr>
  56. </table>
  57. </div><br /><br />
  58.  
  59. <div id="wew"></div>
  60. <div id="zew"></div>
  61.  
  62. </body>
  63. </html>


--------------------
Go to the top of the page
+Quote Post
wojtektorr
post
Post #8





Grupa: Zarejestrowani
Postów: 27
Pomógł: 0
Dołączył: 19.02.2011

Ostrzeżenie: (10%)
X----


W IE 8 nie działa, za niedziałanie odpowiadają te linie: document.test.in.disabled=true;
document.test.out.disabled=false;
Go to the top of the page
+Quote Post
Kshyhoo
post
Post #9





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




Cytat(wojtektorr @ 10.02.2014, 10:22:59 ) *
W IE 8 nie działa

W IE mało co działa wink.gif


--------------------
Go to the top of the page
+Quote Post
owca_82
post
Post #10





Grupa: Zarejestrowani
Postów: 77
Pomógł: 8
Dołączył: 22.04.2012

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


Do "inputów" odwołuj się poprzez atrybut "name" a nie id
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 Aktualny czas: 20.08.2025 - 11:53