JS Transform HTML escape character
Get rid of HTML tags
function removehtmltab (tab) {return
tab.replace (/<[^<>]+?>/g, ');//delete all HTML tags
}
Convert ordinary character to signifier
function Html2escape (sHtml) {return
shtml.replace (/[<>&)]/g,function (c) {return {' < ': ' < ', ' > ': ' > ', ' & ': ' & ', ' ' ': ' " '} [c];});
Convert symbol to ordinary character
function escape2html (str) {
var arrentities={' lt ': ' < ', ' GT ': ' > ', ' nbsp ': ', ' amp ': ' & ', ' quot ': ' '};
Return Str.replace (/& (Lt|gt|nbsp|amp|quot),/ig,function (all,t) {return arrentities[t];}
Turn to Space
function Nbsp2space (str) {
var arrentities = {' nbsp ': '};
Return Str.replace (/& (nbsp);/ig, function (all, t) {return arrentities[t]})
}
Carriage return to BR label
function return2br (str) {return
str.replace (/\r?\n/g, "<br/>");
}
Remove the beginning end line break and convert 3 consecutive lines to 2 lines of wrapping
function Trimbr (str) {
str=str.replace ((\s| ) *\r?\n) {3,}/g, "\r\n\r\n");/limit up to 2 lines of wrapping
str= Str.replace ((\s| ) *\r?\n) +/g, ')//purge opening line/^
((str=str.replace) \s| ) *\r?\n, "); Clear end Line wrap return
str;
}
Combine multiple contiguous spaces into one space
function Mergespace (str) {
str=str.replace (/(\s| ) +/g, ");
return str;
}
JS Code decoding
I. Definition and usage
The encodeURI () function encodes a string as a URI.
Grammar
encodeURI (uristring)
Parameter description
uristring required. A string that contains the URI or other text to encode.
return value
A copy of the uristring in which some of the characters will be replaced by the hexadecimal escape sequence.
Description
The method does not encode ASCII letters and numbers, and does not encode these ASCII punctuation marks:-_. ! ~ * ' ().
The purpose of this method is to encode the URI completely, so that the encodeURI () function is not escaped for the following ASCII punctuation that has special meaning in the URI:;/?:@&=+$,#
Tips and comments
Tip: If the URI component contains delimiters, for example? and #, you should encode each component separately using the encodeURIComponent () method.
The decoding of this method is decodeURI ()
II. Definitions and usage
The escape () function encodes the string so that it can be read on all computers.
Grammar
Escape (String)
Parameter description
String required. The string to be escaped or encoded.
return value
A copy of the encoded string. Some of these characters are replaced with the 16-in escape sequence.
Description
The method does not encode ASCII letters and numbers, and does not encode the following ASCII punctuation:-_. ! ~ * ' (). All other characters will be replaced by escape sequences.
Tips and comments
Tip: You can use Unescape () to decode an escape () encoded string.
Note: ECMAScript v3 against using this method, the application uses decodeURI () and decodeuricomponent () to replace it.
Three, JavaScript encodeuricomponent () function
Definitions and usage
The encodeURIComponent () function encodes a string as a URI component.
Grammar
encodeURIComponent (uristring)
Parameter description
uristring required. A string that contains the URI component or other text to encode.
return value
A copy of the uristring in which some of the characters will be replaced by the hexadecimal escape sequence.
Description
The method does not encode ASCII letters and numbers, and does not encode these ASCII punctuation marks:-_. ! ~ * ' ().
Other characters (such as:;/?:@&=+$,# the punctuation marks used to separate the URI components) are replaced by one or more hexadecimal escape sequences.
Tips and comments
Tip: Note the difference between the encodeURIComponent () function and the encodeURI () function, which assumes that its arguments are part of the URI (such as protocol, host name, path, or query string). Therefore, the encodeURIComponent () function escapes the punctuation marks used to separate parts of the URI.
This method decodes the way decodeuricomponent