Jump to content
php.lv forumi
  • 0

javascript taimeris


xmas12

Question

5 answers to this question

Recommended Posts

  • 0
<div id="sek">20</div>
<script type="text/javascript">
var taimers = null;

function skaitamSek(sec){
 if (taimers) { clearTimeout(taimers); }
 taimers = setTimeout(function(){
  document.getElementById('sek').innerHTML = --sec;
  if (sec <= 0) { 
   document.getElementById('sek').innerHTML = 'Done';
  }
  else {
    skaitamSek(sec);
  }
 },1000);
}

skaitamSek(20);

</script>

Link to comment
Share on other sites

  • 0

setInterval():

<div id="sek">20</div>
<script type="text/javascript">
var
	s = document.getElementById("sek"),
	interval = window.setInterval(function(){
		if (s.innerHTML <= 0)
		{
			window.clearInterval(interval);
			s.innerHTML = 'Done';
		}
		else
		{
			s.innerHTML = --s.innerHTML;
		}
	},
1000);

</script>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...