Single and double quotes in JavaScript resolution

Source: Internet
Author: User

When you use JavaScript to display messages or pass character data, you often encounter a single quotation mark (') or double quotation mark (") in your data, which often results in JavaScript errors. The general use of this/' or/' solution.

For example:

[JavaScript]View Plaincopy
    1. Alert ("This is test" message"!");
    2. Alert (' This is test ' message'! ');

It is usually changed to the following statement

[C-sharp]View Plaincopy
    1. Alert ("This is Test/" message/"!");
    2. Or
    3. Alert ("This is test ' message '!");
    4. Alert (' This is Test/' message/'! ');

If the above is used only in scripts or not too complex data character connections, this problem has been solved.

However, if there is a more complex data character connection, especially some JavaScript statements that are combined by the server, consider using the single quotation mark (') and the double quotation mark (") as the escape sequence (escape sequence) output.

For example, the above statement can be converted into the following format:

[JavaScript]View Plaincopy
    1. Alert ("This is test/u0022message/u0022!");
    2. Alert (' This is test/u0027message/u0027! ');

Supplement some of the commonly used codes

Character Description Unicode escape sequence
Long Dash (-)/u2014
Registration symbol (R)/u00ae
Copyright symbol (c)/u00a9
Trademark symbol (?) /u2122
Euro sign (€)/u20ac
Back slash (/)/u005c
Forward slash (/)/u002f
Left Curly brace ({)/u007b
Closing curly braces (})/u007d
Less than sign (<)/u003c
Greater than sign (>)/u003e
asterisk (*)/u002a
& &amp;
' &apos; (/u0027)
"&quot; (/u0022)
< &lt;
> &gt;

Single and double quotes in JavaScript resolution

Related Article

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.