After a long vacation, I had some trouble returning to the company. I was interrupted in my previous study plan and work plan. I didn't even know what to do when I came back. So I ran to my colleague's blog and came back to read my previous notes. Now I will continue to learn JavaScript.
A valid uri (Uniform Resource Identifier) cannot contain certain characters, such as spaces. Therefore, the URI must be encoded by: encodeuri () and encodeuricomponent (),
The encoding decoding methods include decodeuri () and decodeuricomponent ().
Encodeuri () encoding codeOnlyDecodeuri () Solution
Encodeuricomponent () CodeOnlyDecodeuricomponent () solution,
Encodeuri (): used to encode the complete URI. It does not encode special characters in the URI, such as colons, front slashes, question marks, and pound signs.
var str0=encodeURI("http://www.cnblogs.com/ 2012/ 71.html");
Results: http://www.cnblogs.com/%202012/%2071.html
Only spaces are encoded.
Encodeuricomponent (): used to encode a part of a URI. It encodes all non-standard characters in the URI.
var str1=encodeURIComponent("http://www.cnblogs.com/ 2012/ 71.html");
Result: http%3a%2f%2fwww.cnblogs.com%2f%202012%2f%2071.html
Encode all non-standard characters