How to handle single quotes and double quotes in JavaScript _ javascript skills

Source: Internet
Author: User
Contains single quotes () or double quotation marks (& quot;), which may cause JavaScript errors. This is generally solved by using or & quot;. When JavaScript is used to display messages or transmit character data, it is often encountered that the data contains single quotation marks (') or double quotation marks ("), such statements often cause JavaScript errors. This is generally solved by/'or.

For example:

Alert("this is test "message"!"); Alert('this is test 'message'!');

It is generally changed to the following statement:

Alert ("this is test/" message /"! "); // Or Alert (" this is test 'message '! "); Alert ('this is test/'message /'! ');

If the preceding code is only used in the script or does not have too complex data character connections, this problem has been solved.

However, if complicated data character connections exist, you can consider the single quotation marks (') and double quotation marks (") when using some JavaScript statements combined by the server ("), output with an escape sequence (escape sequence.

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

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

Add some common codes

Character Description Unicode escape sequence
Long dash (-)/u2014
Registration symbol (R)/u00AE
Copyright symbol (c)/u00A9
Trademark (?) /U2122
Euro sign (?) /U20AC
Backslash (/)/u005C
Forward slash (/)/u002F
Left braces ({)/u007B
Right braces (})/u007D
Yu no. (<)/u003C
Greater than (>)/u003E
Asterisk (*)/u002A
&&
''(/U0027)
"" (/U0022)
<
>

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.