v = window.setInterval( “displayTime()”,1000)
形参为函数名,每隔?毫秒执行一次函数,返回一个值V
window.clearInterval(v) 可停止周期调用
例如:
window.onload = function(){
document.getElementById("displayTimeBtn" ).onclick = function(){
//每隔1s调用一次displayTime()函数(设置周期性调用。)
//返回值是一个可以取消周期性调用的value.
v = window. setInterval( "displayTime()",1000)
document.getElementById("stopTimeBtn" ).onclick = function()E
//停止周期性的调用.
window.clearInterval(v)
function displayTime(){
var nowTime = new Date();
document.getElementById( "timediv" ).innerHTML = nowTime.toLocaleString();