当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 通过js控制时间,一秒一秒自己动的实例

通过js控制时间,一秒一秒自己动的实例

2017年12月12日  | 移动技术网IT编程  | 我要评论

1、第一种形式

 <html>
 <head>
 <title>时间</title>
 <script type="text/javascript">
setinterval("showtime()", 1000);
function showtime() {
var date = new date();
var time = date.gethours() + ":" + date.getminutes() + ":"
+ date.getseconds();
document.getelementbyid("timebox").value = time;
}
</script>
 </head>
 <body>
 <div style="text-align:center;">
  当前时间:<input type="text" name="timebox" id="time" />
 </div>
 </body>
</html>

2、第二种形式

<html>
 <head>
 <title>时间</title>
 <script type="text/javascript">
 //获得当前时间,刻度为一千分一秒 
 function showlefttime() {  
 var now = new date();  
 var year = now.getfullyear();  
 var month = now.getmonth() + 1;  
 var day = now.getdate();  
 var hours = now.gethours();  
 var minutes = now.getminutes();  
 var seconds = now.getseconds();  
 document.all.show.innerhtml = "" + year + "年" + month + "月" + day + "日</br> " + hours + ":" + minutes + ":" + seconds + ""; 
 //document.getelementbyid("show").innerhtml = "" + year + "年" + month + "月" + day + "日</br> " + hours + ":" + minutes + ":" + seconds + "";  
  
 //一秒刷新一次显示时间 
 settimeout(showlefttime, 1000); 
 } 
 
 </script> 
 </head>
 <body onload="showlefttime()">
 <label id="show"></label><br/>
 <!-- <script type="text/javascript">
 showlefttime();
 </script> -->
 </body>
</html>

以上这篇通过js控制时间,一秒一秒自己动的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网