1 代码示例

  1. <script>
  2. function fnShow(name, age){
  3. alert("ok" + name + age);
  4. // 销毁定时器tid1
  5. clearTimeout(tid1)
  6. }
  7. // 根据时间间隔调用一次函数的定时器
  8. // 1-定时器要执行的函数, 2-时间间隔(ms), 3..-参数
  9. var tid1 = setTimeout(fnShow, 2000, "李四", 20);
  10. // 根据时间间隔循环调用函数的定时器
  11. var tid2 = setInterval(fnShow, 3000, "王五", 30);
  12. </script>