Text Box breaks are displayed in various browsers using JSON.

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.