Atitit.js string content escape JS processing html

Source: Internet
Author: User

Atitit.js string content escape js processing HTML

1 .  JS handling HTML problems 1

2 .  JS 's string content escape 1

3 .  The following table lists the remaining special characters that can be added to a text string using a backslash: 1

4 .  --code 2

1.JS handling HTML problems

Quotation mark problem. The statement interruption issue caused by carriage return:

2.JS 's string content escape

A carriage return

There's a newline escape.

One quote escape:

Author:: Old Wow's paw attilax Ayron, email:[email protected]

Reprint please indicate source: http://www.cnblogs.com/attilax/

3.The following table lists the remaining special characters that can be added to a text string using a backslash:

Code

Output

\‘

Single quotation marks

\"

Double quotes

\&

and number

\\

Back slash

\ n

Line break

\ r

Carriage return character

\ t

Tabs

\b

Backspace

\f

Page break

4.--code

public class  encodex {

public static   void  main (string[]  args )  {

string   s = "Window.document.getElementById ( ' editor '). value= ' \ "aaa\" ' "

s Span style= "Font-family:consolas; Color: #000000; font-size:12pt; " >=filex. ( "C:\\1.txt" );

System. out . println (jsencode( s));

}

Public static string Jsencode (String p2_txt) {

//  TODO auto-generated Method Stub

string   = ;

string    =  .replaceall ( doublequoto Span style= "Font-family:consolas; Color: #000000; font-size:12pt; " >,  );

return replaceall;

}

Public static string Jsencodesinglequoue (String p2_txt) {

//  TODO auto-generated Method Stub

string   = "\" ;

String ReplaceAll  =  P2_txt . ReplaceAll (doublequoto, "\\\\\");

  ReplaceAll = ReplaceAll. ReplaceAll ("\ r", "\\\\r"); ReplaceAll = ReplaceAll. ReplaceAll ("\ n", "\\\\n");

return replaceall;

}

Atitit.js string content escape JS processing html

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.