亲爱的老师,我来交作业了,麻烦您帮我检查一下呢!⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄

来源:3-13 编程练习

im镇辉

2021-06-25 11:30:00

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Document</title>
    <style>
        div {
            width: 300px;
            margin: 20px 0;
            line-height: 30px;
            background: yellowgreen;
        }
    </style>
</head>
<body>
    <button id="start">开始</button>
    <button id="stop">停止</button>
    <div id="box"></div>
    <script>
        const startBtn = document.getElementById('start')
        const stopBtn = document.getElementById('stop')
        const box = document.getElementById('box')
        var show = {
            content: "Hello World ",
            timer: null,
            
            start: function () {
                // 在此补充代码
                clearInterval(this.timer)
                console.log(this.timer)     //null
                this.timer = setInterval(() => {
                    box.innerHTML += show.content;
                }, 1000);
            },
            stop: function () {
                console.log(this.timer)    //null
                // 在此补充代码
                clearInterval(this.timer)
            },
        }
        // 在此补充代码
        startBtn.addEventListener('click', function () {
            show.start();
        }, false)
        stopBtn.addEventListener('click', function () {
            show.stop();
        }, false)
    </script>
</body>
</html>


写回答

1回答

好帮手慕久久

2021-06-25

同学你好,代码正确,很棒,祝学习愉快!

0

0 学习 · 15276 问题

查看课程