Summary of Textarea line break issues in HTML

Summary of Textarea line break issues in HTML
Recently, I encountered a problem of whether the data can be truly stored row by row when transferred to Textrea. Here is a summary:

Problem description:
For example, get data into a TextArea, such as "AAA BBB", and want to store this text in the TextArea in real lines, rather than displaying it in lines (the so-called real line storage means that the data of this TextArea is still stored in lines when it is posted to the Textarea of ​​another page)

Problem Solved 1:
When the data is submitted at the beginning, the format is AAA<BR />BBB, but this is to display line breaks. In fact, it is not really stored in rows in the TextArea. Because when it is submitted to another TextArea, it will display AAABBB instead of line breaks. Therefore, it is only displayed as stored in rows.

Question Basics:
The line break in HTML is <BR />, while the line break in TextArea is /n

Problem Solved 2:
Submit the data first and then use Javascript to replace <BR /> and /n. When submitting, <BR /> is still used as a separator. After submitting,

Copy code
The code is as follows:

<script>
// Line break and carriage return
var haha=document.getElementById("SendTextArea").value;
haha=haha.replace('
','/n');
document.getElementById("SendTextArea").value=haha;
</script>

That’s it!

<<:  How can the front end better display the 100,000 pieces of data returned by the back end?

>>:  28 Famous Blog Redesign Examples

Recommend

Use Docker to create a distributed lnmp image

Table of contents 1. Docker distributed lnmp imag...

Detailed explanation of fs module and Path module methods in Node.js

Overview: The filesystem module is a simple wrapp...

Detailed explanation of several storage methods of docker containers

Table of contents Written in front Several storag...

How to apply TypeScript classes in Vue projects

Table of contents 1. Introduction 2. Use 1. @Comp...

A complete list of commonly used HTML tags and their characteristics

First of all, you need to know some characteristi...

Design of image preview in content webpage

<br />I have written two articles before, &q...

Install .NET 6.0 in CentOS system using cloud server

.NET SDK Download Link https://dotnet.microsoft.c...

Two ideas for implementing database horizontal segmentation

introduction With the widespread popularity of In...

Summary of several common ways to abbreviate javascript code

Table of contents Preface Arrow Functions Master ...

A brief discussion on the characteristics of CSS float

This article introduces the characteristics of CS...

js code to realize multi-person chat room

This article example shares the specific code of ...