![]()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.box{
width: 150px;
height: 150px;
background-color: #336;
margin:100px auto;
text-align: center;///只给box设置对其方式就可以了
}
.box p{
line-height:25px;
font-size: 12px;
color:#fff;
}
.box span{
display: block;
width: 75px;
height: 75px;
margin: 0 auto;
color:red;
font-size: 50px;
background-color: #333;
}
</style>
<script>
window.onload=function()
{
var box=document.getElementById("box");
var childs=box.children;
var date=new Date();
var arr=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
childs[1].innerHTML=date.getDate();
childs[0].innerHTML=date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"号"+""+arr[date.getDay()];
///注意在月份获取时一定要加一,星期获取时要通过数组的方式来得到
}
</script>
</head>
<body>
<div class="box" id="box">
<p></p>
<span></span>
</div>
</body>
</html>