<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>文字转换工具:横竖版文字转换器,一键复制清空</title>
    <style>
        .container {
            width: 90%;
            max-width: 800px;
            margin: 0 auto;
            text-align: center;
        }
        h1 {
            font-size: 32px;
            margin-bottom: 20px;
        }
        textarea {
            width: 100%;
            height: 200px;
            padding: 10px;
            margin-bottom: 20px;
            border: 1px solid #ccc;
            resize: none;
            font-size: 18px;
            font-family: '微软雅黑', 'Microsoft Yahei', sans-serif;
            line-height: 1.5;
            box-sizing: border-box;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            font-size: 18px;
            cursor: pointer;
            margin-bottom: 20px;
        }
        .result {
            width: 100%;
            height: 200px;
            padding: 10px;
            border: 1px solid #ccc;
            font-size: 18px;
            font-family: '微软雅黑', 'Microsoft Yahei', sans-serif;
            line-height: 1.5;
            box-sizing: border-box;
            margin-bottom: 20px;
        }
        .copy-btn {
            display: inline-block;
            color: #fff;
            border-radius: 3px;
            cursor: pointer;
            margin-left: 10px;
        }
        .clear-btn {
            display: inline-block;
            color: #fff;
            background-color: #f44336;
            border-radius: 3px;
            cursor: pointer;
            margin-left: 10px;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function() {
            $('button').click(function() {
                var text = $('textarea').val().trim();
                if (text !== '') {
                    var result = '';
                    for (var i = 0; i < text.length; i++) {
                        result += text[i] + '
';
                    }
                    $('.result').val(result);
                } else {
                    alert('请输入要转换的文字!');
                }
            });
<pre><code>        $('.copy-btn').click(function() {
            var result = $('.result').val();
            if (result !== '') {
                var temp = $('&lt;textarea&gt;').css({
                    position: 'absolute',
                    left: '-9999px'
                }).appendTo($('body')); // 将临时元素添加到body中
                temp.val(result).select();
                document.execCommand('copy');
                temp.remove(); // 删除临时元素
                alert('已成功复制到剪贴板!');
            } else {
                alert('请先转换文字!');
            }
        });

        $('.clear-btn').click(function() {
            $('textarea').val('');
            $('.result').val('');
        });
    });
&lt;/script&gt;
</code></pre>
</head>
<body>
    <div class="container">
        <h1>文字转换工具:横竖版文字转换器,一键复制清空</h1>
        <textarea placeholder="请输入要转换的文字"></textarea>
        <button>转换</button>
        <div style="margin-top: 8px;"></div>
        <textarea class="result" placeholder="转换后的文字"></textarea>
        <button class="copy-btn">复制</button>
        <button class="clear-btn">清空</button>
    </div>
</body>
</html>
文字转换工具:横竖版文字转换器,一键复制清空

原文地址: https://www.cveoy.top/t/topic/mK7Z 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录