javaScript中的window.setInterval(“函数名”,相隔时间);
函数名要求是全局函数
例如
window.onload = function(){
/*
var skip = function (){
document.getElementById("time").innerHTML = document.getElementById("time").innerHTML - 1;
}
*/
function skip(){
document.getElementById("time").innerHTML = document.getElementById("time").innerHTML - 1;
}
window.setInterval("skip()",1000);
}
<span id="time">4</span>
这两个函数在调用过程中是会出错的,因为skip是局部函数(在window.onload函数下)
更正
吧var 去掉函数就成了全局函数
window.onload = function(){
skip = function (){
document.getElementById("time").innerHTML = document.getElementById("time").innerHTML - 1;
}
window.setInterval("skip()",1000);
}
<span id="time">4</span>