Write it up front, design it according to the requirements. The textarea tag automatically recognizes the height and then increases the height as the user enters the content.

try

The idea is to set the contenteditable property of HTML to true so that adding content automatically increases the height without scrolling.

The results of

Because div cannot recognize some newline symbols and escape carriage returns, the content displayed is different from the content returned by the client, so this scheme is not feasible for the time being.

Current implementation

The total number of lines in the current text is determined by automatically counting the word count of the line feed and comments within the line feed interval. Then dynamically set the number of rows in the current textarea text box.

supplement

Because later in the development time, found a CSS property setting. HTML elements can automatically recognize special meaning escapes, so that line breaks can be implemented automatically.

CSS = white-space: pre-line.

Contenteditable =”true” ADAPTS to text field editing with white-space pre-line of CSS attributes

Write in the end, life in attendance, not to obtain.