Thread View: pl.comp.lang.javascript
2 messages
2 total messages
Started by zlotowinfo
Sat, 23 Feb 2013 22:45
co źle robię timer
Author: zlotowinfo
Date: Sat, 23 Feb 2013 22:45
Date: Sat, 23 Feb 2013 22:45
9 lines
1181 bytes
1181 bytes
<form name=dupa><input name=dupa></form>
for(i=0;i<4;i++)setTimeout("document.dupa.dupa.value='"+i+"'",1000);
pokazuje sie tylko 3
--
http://glosuj.zasms.pl/?glosowania/voip/operatorzy/
http://glosuj.zasms.pl/?glosowania/voip/najgorszy_operator/
http://glosuj.zasms.pl/?glosowania/finanse/banki/
Re: co źle robię timer
Author: Roman Dobosz
Date: Sun, 24 Feb 2013 10:36
Date: Sun, 24 Feb 2013 10:36
34 lines
1771 bytes
1771 bytes
On Sat, 23 Feb 2013 23:45:06 +0100
"zlotowinfo" <dupa@dupa.xx> wrote:
> <form name=dupa><input name=dupa></form>
> for(i=0;i<4;i++)setTimeout("document.dupa.dupa.value='"+i+"'",1000);
>
> pokazuje sie tylko 3
Robisz dokładnie to:
setTimeout("document.dupa.dupa.value='1'",1000);
setTimeout("document.dupa.dupa.value='2'",1000);
setTimeout("document.dupa.dupa.value='3'",1000);
czyli trzy razy rejestrujesz akcje dla niezależnych wywołań
setTimeout, wszystkie się wywołują, ale tak naprawdę widzisz tylko
efekt ostatniego wywołania.
Prawdopodobnie chcesz zrobić to:
<input id="inpt">
var timer = function(){
var inpt = document.getElementById("inpt");
inpt.value = (parseInt(inpt.value, 10) || 0) + 1;
if (inpt.value < 3){
setTimeout(timer, 3000);
}
}
window.onload = timer;
--
-^- _ coś tam w tle sobie gra, np:
_ /O)_\// Haujobb - Centuries in Me
(_(|__(_(_) grf.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads