这次给大家带来js控制时间每秒自己运动,js控制时间每秒自己运动的注意事项有哪些,下面就是实战案例,一起来看一下。
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>
<p style="text-align:center;">
当前时间:<input type="text" name="timebox" id="time" />
</p>
</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控制时间每秒自己运动的详细内容。