escape和unescape知识点

decodeURI() 函数可对 encodeURI() 函数编码过的 URI 进行解码。

encodeURI() 函数可把字符串作为 URI 进行编码

<script>

var uri="my test.asp?name=ståle&car=saab";
document.write(encodeURI(uri)+ "<br>");
document.write(decodeURI(uri));

</script>

运行结果:

my%20test.php?name=st%C3%A5le&car=saab
my test.asp?name=ståle&car=saab

escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串。

该方法不会对 ASCII 字母和数字进行编码,也不会对下面这些 ASCII 标点符号进行编码: * @ - _ + . / 。其他所有的字符都会被转义序列替换

unescape() 函数可对通过 escape() 编码的字符串进行解码

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>

<script>
var str="Need tips? Visit RUNOOB!";
var str_esc=escape(str);
document.write(str_esc + "<br>")
document.write(unescape(str_esc))
</script>

</body>
</html>

运行结果:

Need%20tips%3F%20Visit%20RUNOOB%21
Need tips? Visit RUNOOB!
原文地址:https://www.cnblogs.com/dazhi151/p/12332239.html