IF TextArea Display Line 1! [Shot Shot 2025-02-21 в 17.32.49.png] и строка 2 IS (http: // localhost: 9001/article/680x_4a9d1136-fafb-40dc-8a47 -72CA0B24BF46.png) , как я могу получить контент Textarea с помощью массива контента линии. Это означает из изображения, я ожидаю, что могу получить массив, как ниже < /p>
["![Screen Shot 2025-02-21 at 17.32.49.png]",
"(http://localhost:9001/article/680x_4a9d ... 24bf46.png)"]
< /code>
my textarea display < /p>
Вот мой код < /p>

Split Textarea
function splitTextarea() {
const textarea = document.getElementById("myTextarea");
const text = textarea.value;
// Step 1: Split by hard line breaks (`\n`)
const lines = text.split("\n");
const renderedRows = []
// Step 2: For each paragraph, split into rows based on textarea width
// const rowsArray = [];
const tempElement = document.createElement("div");
tempElement.style.position = "absolute";
// tempElement.style.visibility = "hidden";
tempElement.style.overflowWrap = "break-word";
tempElement.style.whiteSpace = "pre-wrap"; // Preserve spaces and line breaks
tempElement.style.width = `${textarea.clientWidth}px`; // Match textarea width
tempElement.style.fontFamily = getComputedStyle(textarea).fontFamily; // Match font
tempElement.style.fontSize = getComputedStyle(textarea).fontSize; // Match font size
tempElement.style.lineHeight = getComputedStyle(textarea).lineHeight; // Match line height
// tempElement.style.padding = getComputedStyle(textarea).padding; // Match padding
// tempElement.style.boxSizing = "border-box"; // Match box sizing
document.body.appendChild(tempElement);
lines.forEach(line => {
if (line === '') {
// Handle blank lines
renderedRows.push('');
} else {
let start = 0;
while (start < line.length) {
let end = start;
while (end < line.length) {
const text = line.slice(start, end);
tempElement.textContent = line.slice(start, end);
const computedStyle = window.getComputedStyle(tempElement);
const height = computedStyle.height;
const heightInt = parseInt(height, 10);
// if (text === "2全国各地から厳選された有名焼き芋店やおいもスイーツの専門店が集結し、素材にこだわった極上の焼き芋や多彩な") {
// console.log('heightInt', heightInt)
// }
console.log(text, heightInt)
if (heightInt > 19) {
// console.log('end,', end)
end = end - 1
break;
}
end++;
}
console.log("line", line.slice(start, end))
renderedRows.push(line.slice(start, end));
start = end;
}
}
});
// Clean up
// document.body.removeChild(tempElement);
console.log("Rows Array:", renderedRows);
return renderedRows;
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... n-textarea
Как получить контент каждой строки на Textarea ⇐ Html
Программисты Html
-
Anonymous
1740317851
Anonymous
IF TextArea Display Line 1! [Shot Shot 2025-02-21 в 17.32.49.png] и строка 2 IS (http: // localhost: 9001/article/680x_4a9d1136-fafb-40dc-8a47 -72CA0B24BF46.png) , как я могу получить контент Textarea с помощью массива контента линии. Это означает из изображения, я ожидаю, что могу получить массив, как ниже < /p>
["![Screen Shot 2025-02-21 at 17.32.49.png]",
"(http://localhost:9001/article/680x_4a9d1136-fafb-40dc-8a47-72ca0b24bf46.png)"]
< /code>
my textarea display < /p>
Вот мой код < /p>

Split Textarea
function splitTextarea() {
const textarea = document.getElementById("myTextarea");
const text = textarea.value;
// Step 1: Split by hard line breaks (`\n`)
const lines = text.split("\n");
const renderedRows = []
// Step 2: For each paragraph, split into rows based on textarea width
// const rowsArray = [];
const tempElement = document.createElement("div");
tempElement.style.position = "absolute";
// tempElement.style.visibility = "hidden";
tempElement.style.overflowWrap = "break-word";
tempElement.style.whiteSpace = "pre-wrap"; // Preserve spaces and line breaks
tempElement.style.width = `${textarea.clientWidth}px`; // Match textarea width
tempElement.style.fontFamily = getComputedStyle(textarea).fontFamily; // Match font
tempElement.style.fontSize = getComputedStyle(textarea).fontSize; // Match font size
tempElement.style.lineHeight = getComputedStyle(textarea).lineHeight; // Match line height
// tempElement.style.padding = getComputedStyle(textarea).padding; // Match padding
// tempElement.style.boxSizing = "border-box"; // Match box sizing
document.body.appendChild(tempElement);
lines.forEach(line => {
if (line === '') {
// Handle blank lines
renderedRows.push('');
} else {
let start = 0;
while (start < line.length) {
let end = start;
while (end < line.length) {
const text = line.slice(start, end);
tempElement.textContent = line.slice(start, end);
const computedStyle = window.getComputedStyle(tempElement);
const height = computedStyle.height;
const heightInt = parseInt(height, 10);
// if (text === "2全国各地から厳選された有名焼き芋店やおいもスイーツの専門店が集結し、素材にこだわった極上の焼き芋や多彩な") {
// console.log('heightInt', heightInt)
// }
console.log(text, heightInt)
if (heightInt > 19) {
// console.log('end,', end)
end = end - 1
break;
}
end++;
}
console.log("line", line.slice(start, end))
renderedRows.push(line.slice(start, end));
start = end;
}
}
});
// Clean up
// document.body.removeChild(tempElement);
console.log("Rows Array:", renderedRows);
return renderedRows;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79461307/how-to-get-content-of-each-line-on-textarea[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия