Home  >  Article  >  Web Front-end  >  js setInterval()的用法实例

js setInterval()的用法实例

WBOY
WBOYOriginal
2016-06-01 09:55:03986browse

语法
setInterval(code,millisec[,"lang"])
参数    描述
code    必需。要调用的函数或要执行的代码串。
millisec    必须。周期性执行或调用 code 之间的时间间隔,以毫秒计。
返回值  一个可以传递给Window.clearInterval()从而取消对code的周期性执行的值。

实例

<code><input id="clock" size="35" type="text">
<script type="text/javascript">
function clock() {     
  var t=new Date();     
  document.getElementById("clock").value=t
}
var int=setInterval("clock()",50);
</script>
<button onclick="window.clearInterval(int)">Stop interval</button></code>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn