<script>
//随机16进制的颜色
function getCor(){
var str="#";
var arr=[0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"];
for(var i=0;i<6;i++){
var mt=parseInt(Math.random()*16);
str+=arr[mt];
}
return str;
}
console.log(getCor());
window.onload=function(){
document.getElementById("dv").style.backgroundColor=getCor();
}
</script>
<style>
#dv {
height: 100px;
width: 100px;
background-color: pink;
}
</style>
<div id=dv>
</div>
// 计算日期
function getDate(dt){
var year=dt.getFullYear();
var month=dt.getMonth()+1;
var day=dt.getDay();
var hour=dt.getHours();
var minutes=dt.getMinutes();
var second=dt.getSeconds();
month=month>10?month:"0"+month;
day=day>10?day:"0"+day;
hour=hour>10?hour:"0"+hour;
minutes=minutes>10?minutes:"0"+minutes;
second=second>10?second:"0"+second;
return year+"年"+month+"月"+day+"日"+hour+":"+minutes+":"+second;
}
var da=new Date();
console.log(getDate(da));