Text carriage return

I must allow the user to enter carriage returns in text areas; sort of:

Offer 1
Offer 2
...

I have to keep these carriage returns when loading and saving data. I am using jQuery on the client side and .NET on the server. Any suggestions on how to approach?

Thanks.

+1
source share
3 answers

If "persist" breaks a line ( CRLF ), you mean that you want to display it correctly, as SO does, you need to remember to replace the CRLF pair with <br/>CRLF .

Otherwise, all text will appear sequentially.

+3
source

You do not need to do anything special. What <textarea> does, and if you don’t take much effort to highlight the newlines on the server side, you can load them with the standard string without any problems.

+1
source

Use jQuery.val () hook :

 $.valHooks.textarea = { get: function( elem ) { return elem.value.replace( /\r?\n/g, "\r\n" ); } }; 
+1
source

Source: https://habr.com/ru/post/1311935/


All Articles