用函数重复打印不覆盖的语句

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
        <style type="text/css">
         body{background: #111;}
            #box{margin: 20px auto;width: 500px;height: 800px;border:  1px solid #fff;color: green;}
        } //页面样式可不加
        </style>

</head>
<body>
    <div id="box"></div>
    <script type="text/javascript">

            var o=document.getElementById('box');//获取元素
            show();//先执行一次
            function show() {
                o.innerHTML+='hello worid <br />';//为box赋值,加上原值
                setTimeout(show,1000);//隔一秒执行show
            }
            //setInterval(show,1000);//也可用setInterval外部调用
        </script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_44390947/article/details/86477534