Home >Web Front-end >JS Tutorial >Web page countdown digital clock effect implemented by JS_javascript skills

Web page countdown digital clock effect implemented by JS_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:11:411143browse

The example in this article describes the web page countdown digital clock effect implemented by JS. Share it with everyone for your reference. The specific implementation method is as follows:

Copy code The code is as follows:




Countdown clock implemented in javascript

<script><br> window.onload = function ()<br> {<br> var oCountDown = document.getElementById("countdown");<br> var aInput = oCountDown.getElementsByTagName("input")[0];<br> var timer = null;<br> aInput.onclick = function ()<br> {<br> this.className == "" ? (timer = setInterval(updateTime, 1000), updateTime()) : (clearInterval(timer));<br> this.className = this.className == '' ? "cancel" : '';<br> };<br> function format(a)<br> {<br> return a.toString().replace(/^(d)$/,'0$1')<br> }<br> function updateTime ()<br> {<br> var aSpan = oCountDown.getElementsByTagName("span");<br> var oRemain = aSpan[0].innerHTML.replace(/^0/,'') * 60 parseInt(aSpan[1].innerHTML.replace(/^0/,''));<br> if(oRemain <= 0)<br /> {<br /> clearInterval(timer);<br /> return<br /> }<br /> oRemain--;<br /> aSpan[0].innerHTML = format(parseInt(oRemain / 60));<br /> oRemain %= 60;<br /> aSpan[1].innerHTML = format(parseInt(oRemain));<br /> }<br /> }<br /> </script>



01minutes40seconds

Script Home www.jb51.net Code Effects

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
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