开发者

Jquery multiple countdown on page [closed]

开发者 https://www.devze.com 2023-02-28 17:49 出处:网络
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this
Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 8 years ago.

Improve this question

How to put multiple countdown timers on one page, each countdown pointing out to a different period of time, and of course, not reseting on page-refresh?

I'm wondering开发者_如何转开发 if there exists a jQuery solution for that?

Thank you!


try this:

<input type="text" id="but1" />
<input type="text" id="but2" />
<input type="text" id="but3" />
<input type="button" value="start" onclick="timer(1)" />
<input type="button" value="start" onclick="timer(2)" />
<input type="button" value="start" onclick="timer(3)" />
<input type="button" value="stop" onclick="stoptimer(1)" />
<input type="button" value="stop" onclick="stoptimer(2)" />
<input type="button" value="stop" onclick="stoptimer(3)" />


<script type="text/javascript">
var counts = [];
var xs = [];
for (var i = 1; i < 10; i++) {
  counts.push(i*2);
  xs.push(0);
};




function timer(id)
{
  xs[id]=setTimeout("timer("+id+")",1000);
  counts[id]=counts[id]-1;
  document.getElementById("but"+id).value=counts[id];
  if (counts[id] <1){counts[id]=5;}
}

function stoptimer(id)
{
  clearTimeout(xs[id]);
}

</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消