JavaScript timer example setTimeout implements timer in js

WBOY
Release: 2016-07-25 09:12:44
Original
1148 people have browsed it

例子,setTimeout实现一个简单的计时器。

  1. <script></li> <li>var c=0;</li> <li>var t;</li> <li>var timer_is_on=0;</p></li> <li><p>//js计时器代码</li> <li>function timedCount()</li> <li>{</li> <li>document.getElementById('txt').value=c;</li> <li>c=c+1;</li> <li>t=setTimeout("timedCount()",1000);</li> <li>}</p></li> <li><p>function doTimer()</li> <li>{</li> <li>if (!timer_is_on)</li> <li> {</li> <li> timer_is_on=1;</li> <li> timedCount();</li> <li> }</li> <li>}</li> <li></script>
  2. Click on the button above. The input field will count forever, starting at 0.

复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template