javaScrpit在表面上显示时间

<!DOCTYPE html>
<html>
  <head>
    <title>showtime.html</title>	
    <script type="text/javascript">
		function showTime() {
			var div1 = document.getElementById("div1");
			var d = new Date();
			var y = d.getFullYear();
			var m = d.getMonth() + 1;
			var day = d.getDate();
			var h = d.getHours();
			var mm = d.getMinutes();
			var s = d.getSeconds();
			var time =y+"-"+m+"-"+day+" "+h+":"+mm+":"+s;
			div1.innerHTML = time+"<br />";
			setTimeout(showTime, 1000);
	
		}
		window.onload = showTime;
	</script>
  </head>  
  <body>
    <div id="div1"></div>
  </body>
</html>


 

你可能感兴趣的:(javaScrpit在表面上显示时间)