We can tell that escape () escapes all incoming strings in addition to ASCII letters, numbers, and specific symbols, so it is best not to use this method if you want to encode the URL. encodeURI () is used to encode the entire URI because the legitimate characters in the URI are not converted by encoding. The encodeURIComponent method encodes a single uricomponent (the request parameter) should be the most common, it can be described in the parameters of Chinese, special characters escaped, without affecting the entire URL.
Note the difference between the encodeURIComponent () function and the encodeURI () function, which assumes that its arguments are part of a URI (such as a protocol, hostname, path, or query string). Therefore, the encodeURIComponent () function escapes punctuation marks that are used to separate the various portions of the URI.
One, encodeURI ()//escape characters in a URI
Syntax: encodeURI (URI)//This is often used to solve Chinese garbled problems when coding different AJAX requests.
var str1 = "Hello JavaScript"; var str2 = encodeURI (str1); document.write (STR2); //
Second, decodeURI ()//decode the characters in a URI
Syntax: decodeURI (URI)
var str1 = "Hello JavaScript"; var str2 = encodeURI (str1); document.write (STR2); //var STR3 =// output Hello JavaScript
Three, encodeURIComponent ()//Escape the characters in the URI component
var str1 = "Hello JavaScript"; var str2 = encodeURIComponent (str1); document.write (STR2); // output%e4%bd%a0%e5%a5%bdjavascript
Iv. decodeuricomponent ()//decode a character in a URI component
var str1 = "Hello JavaScript"; var str2 = encodeURIComponent (str1); document.write (STR2); //var STR3 =// output Hello JavaScript
V, Escape ()//Encode a string
Syntax: Escape (value);
var str = "JavaScript hello"; var str1 = Escape (str); document.write (STR1); javascript%20%u4f60%u597d
VI, Unecape ()//decode a string encoded by the escape () function
Window.onload = function () { "javascript hello "var str1 =//var str2 = unescape (str1) ; alert (STR2); Popup javascript Hello}
JavaScript URL escape Escape (), encodeURI (), and decodeURI ()