现在学会了获取当前时间,但还是不太清楚计算两个时间相差天数/小时数的方法不知道后面的课程里会不会有,想学习如何计算时间差,做倒计时的效果
<!doctype html>
<html>
<head>
<meta charset="gbk">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>JS提升篇作业</title>
</head>
<style>
#box{width:100px;height:100px;background:#000}
</style>
<body>
<!--改变背景-->
<div id="box"></div>
<input type="button" onclick='changebg()' value='改变背景'>
<script>
function changebg(){
document.getElementById('box').style.backgroundColor="red";
}
/*function changebg(){
$('#box').css('background','red');
}*/
</script>
<!--给DIV插入文字-->
<div id="box2" style="width:100px;height:100px;background:#ccc;margin-top:10px" onclick='changebg2()'>点击DIV改变内容</div>
<script>
function changebg2(){
document.getElementById('box2').innerHTML="我是要写入BOX2的文字";
}
</script>
<!--获取时间-->
今天是<span id='year'></span>年<span id='month'></span>月<span id='day'></span>日<span id='hour'></span>时<span id='minutes'></span>分<span id='second'></span>秒
<script>
var dat = new Date();
var year = dat.getFullYear();
var month = dat.getMonth()+1;
var day = dat.getDate();
var hour = dat.getHours();
var minutes = dat.getMinutes();
var sec = dat.getSeconds();
document.getElementById('year').innerHTML=year;
document.getElementById('month').innerHTML=month;
document.getElementById('day').innerHTML=day;
document.getElementById('hour').innerHTML=hour;
document.getElementById('minutes').innerHTML=minutes;
document.getElementById('second').innerHTML=sec;
</script>
</body>
</html>