function sleep(s){
s = s || 0
s = parseInt(s) * 1000
let now = +new Date()
let timer = null
return new Promise((resolve, reject)=>{
timer = setInterval(()=>{
if( now + s < +new Date()){
clearInterval(timer)
resolve(true)
}
}, 10)
})
}
window.onload =async function(){
for(var i=5i>0i--)
await sleep(1)
alert('显示图片')
}
</script>
<!doctype html><html>
<head>
<meta charset="utf-8">
<title>倒计时</title>
<script type="text/javascript">
function GetRTime(){
var EndTime= new Date('2014/08/12 16:00:00') //截止时间
var NowTime = new Date()
var t =EndTime.getTime() - NowTime.getTime()
var d=Math.floor(t/1000/60/60/24)
var h=Math.floor(t/1000/60/60%24)
var m=Math.floor(t/1000/60%60)
var s=Math.floor(t/1000%60)
document.getElementById("t_d").innerHTML = d + "天"
document.getElementById("t_h").innerHTML = h + "时"
document.getElementById("t_m").innerHTML = m + "分"
document.getElementById("t_s").innerHTML = s + "秒"
}
setInterval(GetRTime,1000)
</script>
</head>
<body>
<div id="CountMsg" class=HotDate>
<span id="t_d"></span>
<span id="t_h"></span>
<span id="t_m"></span>
<span id="t_s"></span>
</div>
</body>
</html>
<body><div id="timer"></div>
<script type="text/javascript" language="javascript">
var endDate=new Date(2010,11,11,17,05,40)//年月日时分秒,月要减去1
(function daoJiShi()
{
var now=new Date()
var oft=Math.round((endDate-now)/1000)
var ofd=parseInt(oft/3600/24)
var ofh=parseInt((oft%(3600*24))/3600)
var ofm=parseInt((oft%3600)/60)
var ofs=oft%60
document.getElementById('timer').innerHTML='还有 '+ofd+' 天 ' +ofh+ ' 小时 ' +ofm+ ' 分钟 ' +ofs+ ' 秒'
if(ofs<0){document.getElementById('timer').innerHTML='倒计时结束!'return}
setTimeout('daoJiShi()',1000)
}())
</script>
</body>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)