<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<input type="button" value="开始" onclick="st()" />
<input type="button" value="结束" onclick="cl()" />
<!-- window -->
<script>
window.alert(111);
window.confirm("刪除嗎?")
function t(){
console.log("111111")
}
function st(){
id = setInterval("t()",1000);
}
function cl(){
clearInterval(id);
}
var iq = setTimeout(t(),1000);
clearTimeout(iq);
</script>
</body>
</html>
setInterval()
与setTimeout()
的区别:
setInterval()
方法会不停地调用函数,直到 clearInterval()
被调用或窗口被关闭;setTimeout()
只执行 code 一次,如果要多次调用,请使用setInterval()
或者让 code 自身再次调用setTimeout();