<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>周期性执行代码,显示一个时钟,这个时钟显示的是当前的年月日和小时,每秒钟刷新一次</title>
<script type="text/javascript">
function myFun() //自定义函数
{
setInterval("setDate()", 1000); //1秒钟调用setDate()一次
}

function setDate() {
var myDate = new Date(); //创建一个日期对象
myForm.showDate.value = myDate.toLocaleString(); //显示日期和时间
}
</script>
</head>

<body onload="myFun()">
<form name="myForm">
当前时间为:
<input type="text" name="showDate" size="35" />
</form>
</body>

</html>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2021-08-10
  • 2021-10-05
  • 2021-12-30
相关资源
相似解决方案