老师我这样写可以么

来源:3-13 编程练习

摩苏尔

2021-05-12 21:42:21

<!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 () {

                // 在此补充代码

                startBtn.onclick=()=>{

                    //设表先关

                    clearInterval(this.timer);

                    this.timer=setInterval(()=>{

                        box.innerHTML+=this.content;

                    },1000);

                }

            },

            stop: function () {

                // 在此补充代码

                 stopBtn.onclick=()=>{

                    clearInterval(this.timer);

                }

            },

        }

         // 在此补充代码

         show.start();

         show.stop();

    </script>

</body>

</html>


写回答

1回答

好帮手慕言

2021-05-13

同学你好,是可以的,效果是对的,继续加油,祝学习愉快~

0

0 学习 · 15276 问题

查看课程