unescape
If we have an encoded data which has been encoded using the escape() function, and we need the actual data, in such case – we use unescape() function. This is also a predefined function in JavaScript and returns decoded data which has been encoded using the escape() function.
如果我们有一个已使用escape()函数编码的编码数据,并且在这种情况下需要实际数据,则可以使用unescape()函数 。 这也是JavaScript中的预定义函数,它返回已使用escape()函数编码的已解码数据。
Example:
例:
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
//Actual string
str1 = "Hello world!";
//encoded string
str2 = escape(str1);
document.write("Actual string is: " + str1);
document.write("<br>");
document.write("Encoded string is: " + str2);
document.write("<br>");
//decoding the string
str3 = unescape(str2);
document.write("Decoded string is: " + str3);
document.write("<br>");
//Actual string
str1 = "email id: [email protected]";
//encoded string
str2 = escape(str1);
document.write("Actual string is: " + str1);
document.write("<br>");
document.write("Encoded string is: " + str2);
document.write("<br>");
//decoding the string
str3 = unescape(str2);
document.write("Decoded string is: " + str3);
document.write("<br>");
</script>
</body>
</html>
Output
输出量
Actual string is: Hello world!
Encoded string is: Hello%20world%21
Decoded string is: Hello world!
Actual string is: email id: [email protected]
Encoded string is: email%20id%3A%[email protected]
Decoded string is: email id: [email protected]
翻译自: https://www.includehelp.com/code-snippets/unescape-function-with-example-in-javascript.aspx
unescape