JavaScript中关于document.write(“0”);的意思

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>JavaScript对象</title>

<script>

var date= new Date();

       document.write("now it's"+ date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日&nbsp;&nbsp;");

var day = date.getDay();

switch(day){

case 0:

   d = "Sunday";

break;

    case 1:

   d = "Monday";

break;

case 2:

   d = "Tuesday";

break;

case 3:

   d = "Wednesday";

break;

case 4:

   d = "Thursday";

break;

case 5:

   d = "Friday";

break;

default:

   d = "Saturday";

}

document.write(d+"&nbsp;");

if(date.getHours()<10){

document.write("0");

}

document.write(date.getHours()+":");

if(date.getMinutes()<10){

document.write("0");

}

document.write(date.getMinutes()+":");

if(date.getSeconds()<10){

document.write("0");

}

document.write(date.getSeconds());

</script>

</head>

<body>

</body>

</html>

慕圣6643023
浏览 1731回答 2
2回答

行走的指尖

意思就是如果时分秒小于10时,就显示成0+要显示的数字形式,比如15:58:03 中的“03”

Sorry灬D

在页面上打印一个0
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript