文字搬运工

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .all
        {
            width: 510px;
            height: 200px;
            border: solid 1px red;
            margin-left: 300px;
            margin-top: 50px;
            position: absolute;
        }
        .first textarea
        {
            width: 200px;
            height: 180px;
            border: solid 1px white;
            background: yellow;
            position: relative;
            float: left;
            margin-left: 6px;
            margin-top: 8px;
        }
        .second
        {
            position: relative;
            float: left;
        }
        .second #btn
        {
            margin-top: 10px;
            background: red;
            color: white;
        }
        .third
        {
            width: 200px;
            height: 180px;
            border: solid 1px white;
            background: deepskyblue;
            position: relative;
            float: left;
            margin-left: 2px;
            margin-top: 8px;
        }
    </style>
    <script>
        window.onload = function () {
            var text = document.getElementById('left');
            var btn = document.getElementById('btn');
            var right = document.getElementById('right');
            var firstnum = document.getElementById('num');
            var secondnum = document.getElementById('number');
            btn.onclick = function () {
                 var str = text.value;
                 var arr = str.split("");
                 var newstr = "";
                 var index = 0;
                 secondnum.innerHTML = arr.length;
                 var timerid = setInterval(function () {
                     left.value = left.value.substr(1);
                    if(firstnum.innerHTML == arr.length)
                    {
                        clearInterval(timerid);
                    }
                    else
                    {
                        newstr = newstr + arr[index];
                        index++;
                    }
                    right.innerHTML = newstr;
                    firstnum.innerHTML = index;
                },100)
            }
        }
    </script>
</head>
<body>
<div class = "all">
    <div class = "first">
        <textarea cols="25" rows="11" id = "left"></textarea>
    </div>
    <div class = "second">
        <input type = "button" value = "把文字右移" id = "btn">
        <p><span id = "num">0</span>/<span id = "number">0</span></p>
    </div>
    <div class = "third" id = "right"></div>
</div>
</body>
</html>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容