<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>
    //设置延时器
  var yyy = window.setTimeout(function(){
        console.log("boom");
        alert("2秒后弹出");
 
    },2000); 

    //清除延时器
    window.clearTimeout(yyy);
    
    </script>
</body>
</html>