js计时器

计时器

<html>
	<head>
		<title>js的内置对象</title>
		<script type="text/javascript">
			/*var rand=parseInt(Math.random()*30+20);
			document.write(rand+"
"); var num1=Math.floor(25.4); document.write(num1+"
"); var num2=Math.ceil(25.4); document.write(num2+"
"); var num3=Math.round(25.4); document.write(num3+"
"); var date=new Date(); var year=date.getFullYear(); var month=date.getMonth()+1; var day=date.getDate(); var hour=date.getHours(); var minute=date.getMinutes(); var second=date.getSeconds(); document.write("现在是:"+year+"年"+month+"月"+day+"日"+hour+":"+minute+":"+second+"
"); */
function time(){ var date=new Date(); var year=date.getFullYear(); var month=date.getMonth()+1; var day=date.getDate(); var hour=date.getHours(); var minute=date.getMinutes(); var second=date.getSeconds(); document.getElementById("year").innerHTML=year+"年"; document.getElementById("month").innerHTML=month+"月"; document.getElementById("day").innerHTML=day+"日"; document.getElementById("time1").innerHTML=hour+":"; document.getElementById("time2").innerHTML=minute+":"; document.getElementById("time3").innerHTML=second; setInterval(time,1000); //Display a clock; } </script> </head> <body onload="time()"> <span id="year"></span> <span id="month"></span> <span id="day"></span> <span id="time1"></span> <span id="time2"></span> <span id="time3"></span> </body> </html>

在这里插入图片描述

你可能感兴趣的:(js)