为了账号安全,请及时绑定邮箱和手机立即绑定

为什么这样写?时间也会隔一秒就更新一次

为什么这样写?时间也会隔一秒就更新一次

_依然_0_0 2016-07-20 16:41:43
  function clock(){    var time=new Date();              var attime= time.getHours()+"-"+time.getMinutes()+"-"+time.getSeconds();    document.getElementById("clock").value = attime;  }()
查看完整描述

2 回答

?
慕仙8196318

TA贡献40条经验 获得超26个赞

更新才怪。楼下正解。

查看完整回答
反对 回复 2016-07-21
?
刚毅87

TA贡献345条经验 获得超309个赞

你这代码缺少定时器吧

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Insert title here</title>>
	</head>

	<body>
		<input type="text" id="clock" />
	</body>
	<script type="text/javascript">
		function clock() {
			var time = new Date();
			var attime = time.getHours() + "-" + time.getMinutes() + "-" + time.getSeconds();
			document.getElementById("clock").value = attime;
		}
		setInterval(clock, 1000);
	</script>
</html>

添加一个定时器,让函数一秒执行一次.

查看完整回答
反对 回复 2016-07-20
  • _依然_0_0
    _依然_0_0
    嗯嗯我知道,慕课里面写是可以显示时间不断更新的,外面不这样!谢谢你
  • 2 回答
  • 0 关注
  • 1066 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信