SoFunction
Updated on 2025-03-10

Use JS to display countdown digital clock effect

This article describes the digital clock effect of web page countdown implemented by JS. Share it for your reference. The specific implementation method is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>javascriptImplemented countdown clock</title>
<style>
body,div{margin:0;padding:0;}
body{color:#fff;font:16px/1.5 \5fae\8f6f\96c5\9ed1;}
#countdown{width:300px;text-align:center;background:#1a1a1a;margin:10px auto;padding:20px 0;}
input{border:0;width:283px;height:50px;cursor:pointer;margin-top:20px;background:url(https:///jscss/demoimg/201210/) no-repeat;}
{background-position:0 -50px;}
span{color:#000;width:80px;line-height:2;background:#fbfbfb;border:2px solid #b4b4b4;margin:0 10px;padding:0 10px;}
</style>
<script>
 = function ()
{
var oCountDown = ("countdown");
var aInput = ("input")[0];
var timer = null;
 = function ()
{
 == "" ? (timer = setInterval(updateTime, 1000), updateTime()) : (clearInterval(timer));
 =  == '' ? "cancel" : '';
};
function format(a)
{
return ().replace(/^(\d)$/,'0$1')
}
function updateTime ()
{
var aSpan = ("span");
var oRemain = aSpan[0].(/^0/,'') * 60 + parseInt(aSpan[1].(/^0/,''));
if(oRemain <= 0)
{
clearInterval(timer);
return
}
oRemain--;
aSpan[0].innerHTML = format(parseInt(oRemain / 60));
oRemain %= 60;
aSpan[1].innerHTML = format(parseInt(oRemain));
}
}
</script>
</head>
<body>
<div >
<span>01</span>minute<span>40</span>Second
<input type="button" value="" />
</div>
</body>
</html>

Learn from this article. I hope this article will be helpful to everyone's JS programming.