Home >Web Front-end >JS Tutorial >Example of replacing line breaks in text fields_jquery
Note: The code passed the test in the actual project. I have omitted some unimportant parts. You can focus on the color-coded parts
Foreplay:
Question: Why do you do this? ?
Answer: There is a project in the project that saves the entered text field text into the database. 'When viewing' obtains the corresponding data from the database and displays it in the text field. During the development, I found that the newline character is obtained using jquery's val() or text() without processing it. There is no newline character in the saved database. Naturally, there is no newline character when it is taken out and displayed! As a result, I wrote the following article... It's a bit long-winded!