jquery动态输入

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title></title>
        <script src="jquery-3.5.1.min.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                var offset = 0;
                var jqSpan = $("span");

                inputEveryOne("暂不恢复旅行社及在线旅游企业出入境团队旅游及“机票+酒店”业务");

                function inputEveryOne(val) {
                    var timer;
                    var arr = [];
                    arr = val.split("");

                    timer = setInterval(function() {
                        jqSpan.text(jqSpan.text() + arr[offset]);

                        if (++offset >= arr.length) {
                            clearInterval(timer);
                            return;
                        }
                    }, 200);
                }
            });
        </script>
    </head>
    <body>
        <h1>
            官方:
            <span></span>
        </h1>
    </body>
</html>

image

posted @ 2020-10-21 21:47  thomas_blog  阅读(221)  评论(0编辑  收藏  举报