A workaround for single and double quotes in JavaScript _javascript tips

Source: Internet
Author: User

When you use JavaScript to display messages or pass character data, you often encounter single quotes (') or double quotes (") in the data, which often cause JavaScript to complain. The general adoption/' or/' solution.

For example:

Alert (' This is test ' message '! '); 
Alert (' This was test ' message '! ');

It is generally changed to the following statement

Alert ("This is Test/" message/"!"); 
or 
Alert ("This was test ' message '!"); 
Alert (' This is test/' message/'! ');

The above problem has been solved if the above is used only in scripts or if there are no data character connections that are too complex.

However, if there are more complex data character connections, especially when some of the server-assembled JavaScript statements can be considered, the single quotation mark (') and the person's double quotation mark (") are used to output the escape sequence (escape sequence).

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

Alert ("This is test/u0022message/u0022!"); 
Alert (' is test/u0027message/u0027! ');

Add some common coding

Character Description Unicode escape sequence
Long dash (-)/u2014
Registry symbol (R)/u00ae
Copyright symbol (c)/U00A9
trademark symbol (?)/u2122
Euro sign (?)/U2 0AC
Backslash (/)/u005c
forward slash (/)/u002f
Opening brace ({)/u007b
closing brace (})/u007d
less than (<)/u003c
greater than sign ;)/u003e
Asterisk (*)/u002a
& &
' (/u0027)
"(/u0022)
< <
>

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.