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