简体   繁体   English

文本字段中的JavaScript时间且未更新

[英]JavaScript time in text field and not updating

Not sure why this JavaScript inst placing the time within the blank text field and updating the time every second. 不知道为什么这个JavaScript将时间放置在空白文本字段中并每秒更新一次时间。 I am trying to get the JavaScript to have a label at the top that says Current Time then a text field that has the current time that is updated every second. 我正在尝试使JavaScript在顶部具有一个标签,该标签显示Current Time,然后是一个文本字段,该文本字段具有每秒更新的当前时间。

    <html>
<head>
<title>Timer</title>
<script language="javascript" type="text/javascript">
var dateform
speed=2000
tid=0;
function dodate()
{
f.date.value=new Date();
tid=window.setTimeout("dodate()",speed);
}
function start(x)
{
  f=x 
  tid=window.setTimeout("dodate()",speed);
}
function cleartid()
{
  window.clearTimeout(tid);
}
</script>
</head>
<body onload="start(document.dateform) ;">
<center>
The Digital Clock
<FORM name="dateform" action="post">
<input type="text" name="date" size=30>
</FORM>
</center>
</body>
</html>

The method you need to use is setInterval and make little changes: 您需要使用的方法是setInterval并进行少量更改:

var dateform
speed=1000
tid=0;
function dodate()
{
f.date.value=new Date();
}
function start(x)
{
  f=x 
  tid=window.setInterval("dodate()",speed);
}
function cleartid()
{
  window.clearTimeout(tid);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM