whycq
2022-05-25 d63e87164a8dd1a178301080dd9a450802149f97
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <button onclick="closeBtn()">关闭</button>
    <button onclick="openBtn()">开始</button>
</body>
<script>
    var i = 1
    var a = true
    setInterval(()=>{
        addI();
    },1000)
    function addI() {
        if (a) {
            console.log("正在打印"+i++)
        }else {
            return;
        }
    }
 
 
    function closeBtn() {
        console.log("暂停打印")
        a = false
    }
    function openBtn() {
        console.log("恢复打印")
        a = true
    }
</script>
</html>