Home > Web Front-end > JS Tutorial > body text

js setInterval()的用法实例

WBOY
Release: 2016-06-01 09:55:03
Original
985 people have browsed it

语法
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>
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!