使用JS顯示倒計(jì)時(shí)數(shù)字時(shí)鐘效果
本文實(shí)例講述了JS實(shí)現(xiàn)的網(wǎng)頁(yè)倒計(jì)時(shí)數(shù)字時(shí)鐘效果。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>javascript實(shí)現(xiàn)的倒計(jì)時(shí)時(shí)鐘</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(http://www.dhdzp.com/jscss/demoimg/201210/btn-1.png) no-repeat;}
input.cancel{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>
window.onload = function ()
{
var oCountDown = document.getElementById("countdown");
var aInput = oCountDown.getElementsByTagName("input")[0];
var timer = null;
aInput.onclick = function ()
{
this.className == "" ? (timer = setInterval(updateTime, 1000), updateTime()) : (clearInterval(timer));
this.className = this.className == '' ? "cancel" : '';
};
function format(a)
{
return a.toString().replace(/^(\d)$/,'0$1')
}
function updateTime ()
{
var aSpan = oCountDown.getElementsByTagName("span");
var oRemain = aSpan[0].innerHTML.replace(/^0/,'') * 60 + parseInt(aSpan[1].innerHTML.replace(/^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 id="countdown">
<span>01</span>分鐘<span>40</span>秒
<input type="button" value="" />
</div>
</body>
</html>
通過(guò)本文的了解。希望本文所述對(duì)大家JS程序設(shè)計(jì)有所幫助。
- javascript實(shí)現(xiàn)數(shù)字時(shí)鐘效果
- vue.js實(shí)現(xiàn)帶日期星期的數(shù)字時(shí)鐘功能示例
- JS+CSS實(shí)現(xiàn)滾動(dòng)數(shù)字時(shí)鐘效果
- js實(shí)現(xiàn)一個(gè)簡(jiǎn)單的數(shù)字時(shí)鐘效果
- javascript實(shí)現(xiàn)滾動(dòng)效果的數(shù)字時(shí)鐘實(shí)例
- JS 實(shí)現(xiàn)倒計(jì)時(shí)數(shù)字時(shí)鐘效果【附實(shí)例代碼】
- JS實(shí)現(xiàn)的網(wǎng)頁(yè)倒計(jì)時(shí)數(shù)字時(shí)鐘效果
- javascript數(shù)字時(shí)鐘示例分享
- html5 canvas js(數(shù)字時(shí)鐘)實(shí)例代碼
- JavaScript實(shí)現(xiàn)動(dòng)態(tài)數(shù)字時(shí)鐘
相關(guān)文章
jsp實(shí)現(xiàn)登錄驗(yàn)證的過(guò)濾器
這篇文章主要為大家詳細(xì)介紹了jsp實(shí)現(xiàn)登錄驗(yàn)證的過(guò)濾器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-04-04
jsp輸出當(dāng)前時(shí)間的實(shí)現(xiàn)代碼
下面小編就為大家?guī)?lái)一篇jsp輸出當(dāng)前時(shí)間的實(shí)現(xiàn)代碼。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06
jsp session.setAttribute()和session.getAttribute()用法案例詳解
這篇文章主要介紹了jsp session.setAttribute()和session.getAttribute()用法案例詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08
jsp 實(shí)現(xiàn)的簡(jiǎn)易mvc模式示例
這篇文章主要介紹了jsp 實(shí)現(xiàn)的簡(jiǎn)易mvc模式,結(jié)合實(shí)例形式簡(jiǎn)單分析了jsp實(shí)現(xiàn)的MVC模式模型、視圖、控制器相關(guān)配置與使用操作技巧,需要的朋友可以參考下2019-11-11
解決JSP開(kāi)發(fā)中Web程序顯示中文三種方法
JSP顯示中文方法小結(jié)2008-11-11
jsp頁(yè)面間傳中文參數(shù)示例(頁(yè)面?zhèn)鲄?shù)編碼)
在url地址欄使用中文傳參數(shù)可能會(huì)是亂碼了,下面我們來(lái)看看正確的jsp中頁(yè)面間傳中文參數(shù)轉(zhuǎn)碼的方法2014-01-01

