为什么分和秒出不了0的值

来源:1-2 时间效果实现

qq_慕沐9265762

2019-04-13 15:03

<!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>无标题文档</title>

<style>

*{ margin:0px; padding:0px;}


#wrap{ height:200px;

width:300px;

margin:100px auto; 

border:2px solid #F00;

line-height:200px; 

text-align:center;}


</style>

<script>

window.onload=function(){

var sj=document.getElementById('sj');

function checkTime(i){

if(i<10){

i="0"+i;

}

return i;

}

show();

    function show(){

var myDate=new Date();

var year=myDate.getFullYear();

var month=myDate.getMonth()+1;

var date=myDate.getDate();

var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]

var hours=myDate.getHours();

var minutes=myDate.getMinutes();

var seconds=myDate.getSeconds();

sj.innerHTML=year+"年"+month+"月"+date+"日"+" "+weekday[myDate.getDay()]+" "+hours+":"+minutes+":"+seconds

minutes=checkTime(minutes);

seconds=checkTime(seconds);

setTimeout(show,1000);

    }

}


</script>


</head>


<body>

<div id="wrap">

    <p id="sj"></p>

</div>

</body>

</html>


写回答 关注

2回答

  • 津庭木3795290
    2019-04-25 02:00:17

    检查和输出的顺序问题

  • qq_慕沐9265762
    2019-04-13 15:06:12

    已解决

倒计时效果

电商网站限时抢购倒计时效果计算思路和方法,前端开发必备技术

55613 学习 · 242 问题

查看课程