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>
01分钟40秒
脚本之家 www.jb51.net 代码特效