<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>文本框内容拼接示例</title>
</head>
<body>
<h3>文本框1:</h3>
<textarea id="text1" rows="6" cols="50"></textarea>
<h3>文本框2:</h3>
<textarea id="text2" rows="6" cols="50"></textarea>
<h3>文本框3:</h3>
<textarea id="text3" rows="6" cols="50"></textarea>
<br>
<button onclick="concatenateText()">点击拼接</button>
<script>
function concatenateText() {
var text1 = document.getElementById("text1").value.split('\n');
var text2 = document.getElementById("text2").value.split('\n');
var text3 = document.getElementById("text3").value.split('\n');
var result = "";
var maxLength = Math.max(text1.length, text2.length, text3.length);
for (var i = 0; i < maxLength; i++) {
if (i < text1.length) {
result += text1[i];
}
if (i < text2.length && text2[i].trim() !== "") {
result += text2[i];
}
if (i < text3.length) {
result += text3[i];
}
result += '\n';
}
document.getElementById("text1").value = result;
}
</script>
</body>
</html>