2个回答
展开全部
<html>
<body>
离半夜12点还有<span id="hour"></span>小时<span id="min"></span>分
</body>
<script>
function countdown() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
h = 23 - h;
m = 59 - m;
m = checkTime(m)
document.getElementById("hour").innerHTML=h;
document.getElementById("min").innerHTML=m;
}
function checkTime(i) {
if (i<10) i = "0" + i;
return i;
}
setInterval("countdown()", 50);
</script>
<html>
追问
我是不是应该加一句来解决字符集的问题,这句有没有错?
追答
没错,还要注意html文件要以对应的编码(utf-8)保存
展开全部
<div> 离半夜12点还有<span id="hour"></span> 小时 <span id="min"></span> 分 <span id="sec"></span> 秒</div>
<script type="text/javascript">
function showtime(){
var tartime = new Date();
var nowtime = new Date();
tartime.setHours(24,0,0,0);
var tartime = tartime.getTime();
var nowtime = nowtime.getTime();
var time = tartime - nowtime;
var seconds = Math.floor(time/1000);
var mins = Math.floor(seconds/60);
var hours = Math.floor(mins/60);
var nowmins = mins%60;
var nowsec = seconds%60;
document.getElementById('hour').innerHTML = hours;
document.getElementById('min').innerHTML = nowmins;
document.getElementById('sec').innerHTML = nowsec;
}
showtime();
setInterval(showtime,1000);
</script>
还加了秒数。倒计时。放在body中
<script type="text/javascript">
function showtime(){
var tartime = new Date();
var nowtime = new Date();
tartime.setHours(24,0,0,0);
var tartime = tartime.getTime();
var nowtime = nowtime.getTime();
var time = tartime - nowtime;
var seconds = Math.floor(time/1000);
var mins = Math.floor(seconds/60);
var hours = Math.floor(mins/60);
var nowmins = mins%60;
var nowsec = seconds%60;
document.getElementById('hour').innerHTML = hours;
document.getElementById('min').innerHTML = nowmins;
document.getElementById('sec').innerHTML = nowsec;
}
showtime();
setInterval(showtime,1000);
</script>
还加了秒数。倒计时。放在body中
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询