setTimeout函數(shù)
讓函數(shù)在一定時(shí)間內(nèi)重新執(zhí)行,遞歸調(diào)用
如果不遞歸調(diào)用則僅執(zhí)行一次
clearTimeout函數(shù)
清除設(shè)置的setTimeout函數(shù)
clearTimeout(timeId);
setInterval函數(shù)
讓函數(shù)在一定時(shí)間內(nèi)重新執(zhí)行迄薄,外部調(diào)用
clearInterval函數(shù)
清除設(shè)置的setInterval函數(shù)
? clearInterval(timeId);
//重點(diǎn) 前端考試
function aaa(){
alert("你好")
}
//setTimeout(aaa(), 5000); //延遲5秒后彈出
//aaa();
//間隔函數(shù)
setInterval("aaa()",5000);
例setInterval ??清除設(shè)置的setTimeout函數(shù)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script language=Javascript>
var timeId;
function hello(){
alert("hello");
}
function do_set(){
timeId = setInterval("hello()",2000);
}
function cInterval(){
clearInterval(timeId);
}
</script>
</head>
<body>
<input type="button" value="setInterval()" onclick="do_set()">
<input type="button" value="clearInterval()" onclick="cInterval()">
</body>
</html>
例setTimeout 清除設(shè)置的setTimeout函數(shù)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script language=Javascript>
var timeId;
function hello(){
alert("hello");
timeId = setTimeout("hello()",2000);
}
function cTimeout(){
clearTimeout(timeId);
}
</script>
</head>
<body>
<input type="button" value="setTimeout()" onclick="hello()">
<input type="button" value="clearTimeout()" onclick="cTimeout()">
</body>
</html>