js超时调用和间歇调用
超时调用
//不建议传递字符串
setTimeout(“alert(‘hello,world’)”,1000);
//推荐使用方式
setTimeout(function(){
alert(‘hello,world’);
},1000);
clearTimeout()来取消
间歇调用
setInterval()方法
setInterval(function(){
alert(‘hello,world’);
},1000);
clearInterval方法取消
用超时调用模拟间歇调用实例
<html>
<head>
<script>