Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Zegarek
Forum PHP.pl > Forum > Po stronie przeglądarki > JavaScript
lojciec14
Witam. Znalazłem niezły zegarek w sieci i chciałem się dowiedzieć, jak go zmodyfikować, żeby usunąć z niego pole tekstowe?

Link: http://webmaster.helion.pl/kurshtml/skrypt/zegarek.htm

Dzięki za pomoc.
skowron-line
tzn jakie pole tekstowe chodzi Tobie o input questionmark.gif
  1. <script language="javascript">
  2. <!--W3e JAVAscript Preset
  3. var timerID = null;
  4. var timerRunning = false;
  5. function stopclock()
  6. {
  7. if(timerRunning)
  8. clearTimeout(timerID)
  9. timerRunning = false;
  10. }
  11.  
  12. function startclock()
  13. {
  14. stopclock();
  15. showtime();
  16. }
  17.  
  18. function showtime()
  19. {
  20. var now = new Date();
  21. var hours = now.getHours();
  22. var minutes = now.getMinutes();
  23. var seconds = now.getSeconds();
  24. var timeValue = "" + ((hours > 12) ? hours - 12 : hours);
  25. timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
  26. timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
  27. timeValue += (hours >= 12) ? " P.M." : " A.M.";
  28. document.getElementById( 'oClock' ) = timeValue;
  29. timerID = setTimeout("showtime()",1000);
  30. timerRunning = true;
  31. }
  32. //-->
  33.  
  34. <div id="oClock"></div>
  35.  
  36. <script>startclock();</script>

*pisane z palca.
lojciec14
Dokładnie chodzi mi o input. Skrypt, który podałeś nie chce ruszyć...
skowron-line
Mówisz i masz
  1. <script language="javascript">
  2. <!--W3e JAVAscript Preset
  3. var timerID = null;
  4. var timerRunning = false;
  5. function stopclock()
  6. {
  7. if(timerRunning)
  8. clearTimeout(timerID)
  9. timerRunning = false;
  10. }
  11.  
  12. function startclock()
  13. {
  14. stopclock();
  15. showtime();
  16. }
  17.  
  18. function showtime()
  19. {
  20. var now = new Date();
  21. var hours = now.getHours();
  22. var minutes = now.getMinutes();
  23. var seconds = now.getSeconds();
  24. var timeValue = "" + ((hours > 12) ? hours - 12 : hours);
  25. timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
  26. timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
  27. timeValue += (hours >= 12) ? " P.M." : " A.M.";
  28.  
  29. document.getElementById( 'oClock' ).innerHTML = timeValue;
  30.  
  31. timerID = setTimeout("showtime()",1000);
  32. timerRunning = true;
  33. }
  34. //-->
  35.  
  36. <body onload="startclock();">
  37. <div id="oClock"></div>
lojciec14
Dzięki. A dałoby radę dołożyć jeszcze napis Godzina: (tutaj wyświetlany zegar) questionmark.gif Chodzi mi o to, że jak przed skryptem postawię napis godzina, to robi mi po nim enter, a chciałbym mieć to wszystko w jednej linii. No i jeszcze jedno. Jak zamienić system 12h na 24h ?
Wicepsik
  1. <script language="javascript">
  2. <!--W3e JAVAscript Preset
  3. var timerID = null;
  4. var timerRunning = false;
  5. function stopclock()
  6. {
  7. if(timerRunning)
  8. clearTimeout(timerID)
  9. timerRunning = false;
  10. }
  11.  
  12. function startclock()
  13. {
  14. stopclock();
  15. showtime();
  16. }
  17.  
  18. function showtime()
  19. {
  20. var now = new Date();
  21. var hours = now.getHours();
  22. var minutes = now.getMinutes();
  23. var seconds = now.getSeconds();
  24. var timeValue = hours;
  25. timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
  26. timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
  27.  
  28.  
  29. document.getElementById( 'oClock' ).innerHTML = timeValue;
  30.  
  31. timerID = setTimeout("showtime()",1000);
  32. timerRunning = true;
  33. }
  34. //-->
  35.  
  36. <body onload="startclock();">
  37. <div id="oClock"></div>


Tak trudno popatrzeć na kod? Nie znam się na javascript i jakoś mi się udało... MYŚL!
skowron-line
  1. document.getElementById( 'oClock' ).innerHTML = "Godzina: "+timeValue;
lojciec14
Dziękuję serdecznie. Wszystko działa jak należy smile.gif Efekt można zobaczyć tutaj: http://oldschoolplayers.pl/index.php?act=uportal tabelka "Dzisiaj po prawej stronie smile.gif
kamil4u
Ja jeszcze dam link do pewnego zegarka : http://rafael.webd.pl/tmp/zegar/ - warto spojrzeć w kod smile.gif
nexis
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  4. <title>Zegarek</title>
  5. <script type="text/javascript">
  6. function showtime()
  7. {
  8. var now = new Date();
  9. var hours = now.getHours();
  10. var minutes = now.getMinutes();
  11. var seconds = now.getSeconds();
  12. var timeValue;
  13.  
  14. timeValue = hours;
  15. timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
  16. timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
  17.  
  18. document.getElementById( 'oClock' ).innerHTML = 'Godzina ' + timeValue;
  19.  
  20. setTimeout("showtime()", 1000);
  21. }
  22. </script>
  23. </head>
  24. <body onload="showtime();">
  25. <div id="oClock"></div>
  26. </body>
  27. </html>
kefirek
  1. <script type="text/javascript">
  2. function czas()
  3. {
  4. var d = new Date();
  5. sekund = (d.getSeconds());
  6. minut = (d.getMinutes());
  7. godzin = (d.getHours());
  8. if (minut<=9)
  9. minut= "0" + minut;
  10. if (sekund <= 9 )
  11. sekund ="0" + sekund;
  12. if (godzin <= 9 )
  13. godzin ="0" + godzin;
  14.  
  15. document.getElementById('div1').innerHTML = "Czas: " + godzin + ":" + minut + ":" + sekund;
  16. }
  17.  
  18. window.setInterval(czas,1000);
  19.  
  20. <div id="div1"></div>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.