Author: Yan
Final Solution:
1. The database stores the carriage return line code "\ r \ n ";
2. Because \ r \ n cannot be directly stored in JSON, you can replace it with <br/> and upload it to the page;
3. On the page, <br/> change back to \ r \ n. The most important thing is that when textarea is displayed, different browsers have different processing methods. Check the Code:
VaR strremark = "";
If (SYS. ie ){
Strremark = data. remark. replace (/<br \/>/GI, "\ r"); // in IE, after the following text (VAL) encoding, \ r is changed to \ r \ n. If \ r \ n is encoded, it is changed to \ r \ n.
} Else {
Strremark = data. remark. replace (/<br \/>/GI, "\ r \ n"); // after the following text (VAL) encoding in other browsers, \ r \ n or \ r \ n
}
// In jquery's text (VAL) method, replace the carriage return linefeed with the corresponding HTML object. Be sure not to use HTML (VAL). textarea is not displayed in IE.
$ ("# Remark"). Text (strremark );
4. However, if you press enter directly in textarea, ie and other browsers will parse the press enter into \ r \ n (the form is uploaded to \ r \ n in the background, here I use struts2 ).
5. If jquery's text (VAL) is not used, how does one encode and assign values to the textarea value?