decodeURI () Definition and usage: the decodeURI () function decodes a URI encoded by the encodeURI () function.
Syntax: decodeURI (uristring)
Parameter description: Uristring required, a string containing the URI group to decode or other text to decode.
Return value: A copy of uristring, where the hexadecimal escape sequence is replaced by the character they represent.
decodeURIComponent () Definition and usage: the decodeURIComponent () function decodes a URI encoded by the encodeURIComponent () function.
Syntax: decodeURIComponent (uristring)
Parameter description: Uristring required, a string that contains the decoded URI component or other text to decode.
Return value: A copy of uristring, where the hexadecimal escape sequence is replaced by the character they represent.
The above is a description of the usage, but there are some problems in the actual use process:
#特殊符号进行进行编码传递参数的时候有一些不一样:
Test code as follows:
<script>
Function Demo () {
var text=escape ("Http://www.w3school.com.cn/My first/#qpp");
alert (text);
}
function Demo1 ()
{
var test1= "Http://www.w3school.com.cn/My first/#qpp"
Alert (encodeURIComponent (test1));
}
function Demo3 ()
{
var test1= "Http://www.w3school.com.cn/My first/#qpp"
Alert (decodeURI (test1));
}
function MyApp (text)
{
var text=unescape (text);
alert (text);
}
</script>
<body>
<input type= "button" onclick= "Demo ()" Value= "Escape"/><br>
<input type= "button" onclick= "Demo3 ()" value= "decodeURI"/><br>
<input type= "button" onclick= "Demo1 ()" value= "encodeURIComponent"/><br>
<input type= "button" onclick= "MyApp (' visit%20w3school%21 ')" value= "Unescape"/><br>
</body>
The test is as follows:
For the above test, it can be helpful to have the # wait for a special character in the query string.
Use and difference between JavaScript decodeURI () and decodeURIComponent ()