JavaScript Window对象SetInterval()方法示例

<html>
<head>
  <textarea id="txt" cols="20" rows="2"></textarea>

  <script type="text/javascript">
	  var int = self.setInterval("myfun()", 1000);
	  function myfun() {
		  var mm = new Date();

		  var t = mm.toLocaleTimeString();
		  document.getElementById("txt").value = t;
	  }
  </script>

</head>
<body>
  <button onclick="int=window.clearInterval(int)">
	  click me</button>

</body>
</html>
JavaScript Window对象SetInterval()方法

JavaScript Window对象SetInterval()方法

JavaScript SetInterval()方法用于在特定时间间隔时反复调用函数。

方法调用函数将一直持续到 ClearInterval() 方法被调用或者窗口关闭。

语法

Window.SetInterval(Function(), Milisecond)
日期:2020-04-18 01:09:28 来源:oir作者:oir