-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
111 lines (72 loc) · 2.63 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>逐行字符串分拆工具</title>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
display: flex;
justify-content: space-around;
align-items: flex-start;
margin-top: 20px;
}
textarea {
width: 45%;
height: 300px;
padding: 10px;
font-size: 16px;
}
button {
margin-top: 20px;
padding: 10px 20px;
font-size: 16px;
}
</style>
</head>
<body>
<div class="container">
<textarea id="inputText" placeholder="在这里粘贴文本..."></textarea>
<div class="button-container">
<button onclick="splitText()">分拆</button>
<button onclick="copyToClipboard()">复制结果</button>
</div>
<textarea id="outputText" placeholder="分拆后的结果会显示在这里..." readonly></textarea>
</div>
<script>
function splitLineInThrees(line) {
// 分割单行文本为每三个字符一组,并用空格连接
return line.match(/.{1,3}/g)?.join(' ') || '';
}
function splitText() {
// 获取输入文本框的内容
const inputText = document.getElementById('inputText').value;
// 按行分割输入文本
const lines = inputText.split('\n');
// 对每一行进行分拆处理
const processedLines = lines.map(line => {
// 移除行首和行尾的空白字符
const cleanLine = line.trim();
// 如果行为空,则返回空字符串
if (!cleanLine) return '';
// 调用函数对单行进行分拆
return splitLineInThrees(cleanLine);
});
// 将处理后的各行重新组合成一个字符串,每行之间用换行符分隔
const resultText = processedLines.join('\n');
// 将分拆后的结果显示在输出文本框中
document.getElementById('outputText').value = resultText;
}
function copyToClipboard() {
const outputText = document.getElementById('outputText');
outputText.select(); // 选择文本框中的所有文本
outputText.setSelectionRange(0, 99999); // 对于移动设备
document.execCommand('copy'); // 复制选中的文本到剪贴板
// 可选:提供反馈给用户
alert('分拆结果已复制到剪贴板!');
}
</script>
</body>
</html>