|
TwojePC.pl © 2001 - 2026
|
 |
A R C H I W A L N A W I A D O M O Ś Ć |
 |
| |
|
Jak odlicza czas Javascript? , kubazzz 30/11/09 21:50 Potrzebuję prosty skrypt, odliczanie milisekund do danej daty i godziny.
Łatwo znaleźć gotowce, ale takie co liczą z dokładnością do sekundy (calcage), ale milisekund nie udało mi się do nich dodać.
W ogóle nie potrzebuję rozbijania na miesiące i dni, wystarczą mi godziny/minuty/sekundy/milisekundy, albo od biedy same milisekundy.SM-S908 - zrobiłem coś takiego, ale to za bardzo zamula przeglądarkę , kubazzz 30/11/09 22:57
może się nie da takiego szybkiego odświeżania?
<html>
<head>
<script type="text/javascript">
var d=new Date("11/30/2009 11:00 PM");
t=new Date();
left = d.getTime()-t.getTime();
document.getElementById('counter').innerHTML = left;
</script>
</head>
<body>
<div id="counter"></div>
</body>
</html>
tzn to nie działa, nie wiem czemu, ja JS znam głównie przez jQuery.
Zrobiłem wariant
while(true)
{
t=new Date();
left = d.getTime()-t.getTime();
$('#counter').text(left);
}
Ale to się muli potwornie bo pętla nie ma żadnego ogranicznika, a dodatkowo jquery się odpala.SM-S908 - .:. , Shneider 30/11/09 23:44
moge zapytac co chcesz osiagnac tym?
moze da sie to ominac, stosujac inny mechanizm..:: Live at Trance Energy ::. - nie wiem czy się da, to powinno być proste, mam lepszy wariant ale dalej nie działa , kubazzz 30/11/09 23:51
<script src="jquery.js" type="text/javascript" charset="UTF-8"></script>
<script type="text/javascript">
$(document).ready(function()
{
function display(){
var d=new Date("12/01/2009 11:00 PM");
var t=new Date();
var left = d.getTime()-t.getTime();
$('#counter').text(left);
setTimeout("display()",1000)
}
display()
});
</script>
i dostaję z konsoli błąd
JavaScript - file://localhost/N:/countdown/count.html
Timeout thread: delay 1000 ms
Error:
name: ReferenceError
message: Statement on line 1: Undefined variable: displaySM-S908
- no niech mi ktoś powie co tu jest źle , kubazzz 1/12/09 00:20
<html>
<head>
<script type="text/javascript">
function display(){
var d=new Date("12/01/2009 11:00 PM");
var t=new Date();
var left = d.getTime()-t.getTime();
document.getElementById("counter").innerHTML = left;
setTimeout('display()',1000);
}
display();
</script>
</head>
<body>
<div id="counter"></div>
</body>
</html>
Firefox:
Błąd: document.getElementById("counter") is null
Plik źródłowy: file:///N:/countdown/count.html
Wiersz: 9
Opera:
JavaScript - file://localhost/N:/countdown/count.html
Inline script thread
Error:
name: TypeError
message: Statement on line 7: Cannot convert undefined or null to ObjectSM-S908 - looknij , celt 1/12/09 00:41
sobie tutaj na ten skrypt moze pomoze
http://www.web-source.net/javascript_tutorial2.htmEverything should be made as simple as
possible, but no simpler - hmm , recydywista 2/12/09 10:56
coś takiego mi się napisało
<html>
<head>
<script type="text/javascript">
function timeLeft(target) {
var now = new Date();
var left = target.getTime() - now.getTime();
var miliseconds = left % 1000;
var seconds = Math.floor(left/1000);
var minutes = Math.floor(seconds/60);
seconds = seconds % 60;
var hours = Math.floor(minutes/60);
minutes = minutes % 60;
document.getElementById('counter').innerHTML = hours + ':' + zeroPad(minutes, 2) + ':' + zeroPad(seconds, 2) + '.' + zeroPad(miliseconds, 3);
setTimeout(function() {timeLeft(target)}, 500);
}
function zeroPad(num,count) {
num += '';
while(num.length < count) num = '0' + num;
return num;
}
</script>
</head>
<body onload="timeLeft(new Date('12/10/2009 11:00 PM'))">
<div id="counter"></div>
</body>
</html>Computers are useless. They can only
give you
answers. |
|
|
|
 |
All rights reserved ® Copyright and Design 2001-2026, TwojePC.PL |
 |
|
|
|