abstrait:<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>js倒計(jì)時(shí)代碼</title><style type="text/
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js倒計(jì)時(shí)代碼</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body{ text-align:center;}
ul, li {
list-style: none;
}
#show_time {
color: #f00;
font-size: 24px;
font-weight: bold;
width:100%;
text-align:center;
padding-top:30px;
}
</style>
</head>
<body>
<div id="show_time"> </div>
<script type="text/javascript">
function countdown(){
var show_time = document.getElementById("show_time");
var endtime = new Date("12/31/2020 23:59:59");//結(jié)束時(shí)間f
var today = new Date();//當(dāng)前時(shí)間
var delta_T = endtime.getTime() - today.getTime();//時(shí)間間隔
if(delta_T < 0){
clearInterval(auto);
show_time.innerHTML = "倒計(jì)時(shí)已經(jīng)結(jié)束";
}
window.setTimeout(countdown,1000);
var total_days = delta_T/(2*24*60*60*1000);//總天數(shù)
var total_show = Math.floor(total_days);//實(shí)際顯示的天數(shù)
var total_hours = (total_days - total_show)*24;//剩余小時(shí)
var hours_show = Math.floor(total_hours);//實(shí)際顯示的小時(shí)數(shù)
var total_minutes = (total_hours - hours_show)*60;//剩余的分鐘數(shù)
var minutes_show = Math.floor(total_minutes);//實(shí)際顯示的分鐘數(shù)
var total_seconds = (total_minutes - minutes_show)*60;//剩余的分鐘數(shù)
var seconds_show = Math.floor(total_seconds);//實(shí)際顯示的秒數(shù)
show_time.innerHTML = "距離2020年還有:" + total_show + "天" + hours_show + "時(shí)" + minutes_show + "分" + seconds_show + "秒";
}
countdown();
</script>
</body>
</html>
演示地址 -> http://47.107.64.136/JS/3/
Professeur correcteur:韋小寶Temps de correction:2019-01-17 09:14:42
Résumé du professeur:寫的很不錯(cuò) 看來關(guān)于時(shí)間的js方法你已經(jīng)掌握的差不多了