Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Javascript] settimeout przy zmianie obrazka
messmaker
post
Post #1





Grupa: Zarejestrowani
Postów: 106
Pomógł: 5
Dołączył: 5.12.2008

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


Oto kod:

  1. <script type="text/javascript">
  2. function changePic(item,icon){
  3.  
  4. if (document.getElementById( 'c' + item ).checked){
  5. document.getElementById( 'i' + item ).src=icon+'_c.gif';
  6. }else{
  7. document.getElementById( 'i' + item ).src=icon+'_u.gif';
  8. }
  9. setTimeout("pngPic('item','icon')",1000 );
  10. }
  11.  
  12. function pngPic(item,icon){
  13. alert('przeszło');
  14. if (document.getElementById( 'c' + item ).checked){
  15. document.getElementById( 'i' + item ).src=icon+'_c.png';
  16. }else{
  17. document.getElementById( 'i' + item ).src=icon+'_u.png';
  18. }
  19. }

  1. <label class="f_checkbox" for="c1"><img src="5.gif" id="i1"><input type="checkbox" id="c1" value="checkbox" onClick="changePic(1,5);"></label>


Kod, jaki jest, każdy widzi (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

Problem w tym, że bydlak nie zmienia src obrazka na png. Po sekundzie od kliknięcia trafnie wyświetla alert, ale na tym kończy zabawę. Alertowanie item wyświetla Undefined, więc pewien trop jest. Niemniej jednak jestem na tyle zielony, że nie mam pojęcia jak to rozgryźć. (IMG:http://forum.php.pl/style_emoticons/default/wstydnis.gif)
Go to the top of the page
+Quote Post
skowron-line
post
Post #2





Grupa: Zarejestrowani
Postów: 4 340
Pomógł: 542
Dołączył: 15.01.2006
Skąd: Olsztyn/Warszawa

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


  1. setTimeout("pngPic("+item+","+icon+")",1000 );


ty miałes same stringi a tak sa przekazywane zmienne które wpadaja do funkcji.
Go to the top of the page
+Quote Post
wookieb
post
Post #3





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




https://developer.mozilla.org/En/DOM/window.setTimeout
Go to the top of the page
+Quote Post
messmaker
post
Post #4





Grupa: Zarejestrowani
Postów: 106
Pomógł: 5
Dołączył: 5.12.2008

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


Dziękować, śmiga (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
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: 17.09.2025 - 14:59