<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>js escape()_unescape()</title> </head> <body> <script> /* 建议使用 encodeURI() encodeURIComponent() decodeURI() decodeURIComponent() 取代 escape() unescape()。 参考: https://www.w3school.com.cn/js/jsref_escape.asp https://www.w3school.com.cn/jsref/jsref_unescape.asp * 知识点: * 1.escape(string) -> 已编码的 string 的副本。其中某些字符被替换成了十六进制的转义序列。 * 可对字符串进行编码,这样就可以在所有的计算机上读取该字符串。 * string,必需。要被转义或编码的字符串。 * 说明: * 1.该方法不会对 ASCII 字母和数字进行编码,也不会对下面这些 ASCII 标点符号进行编码: * * @ - _ + . / 。其他所有的字符都会被转义序列替换。 * 2.可以使用 unescape() 对 escape() 编码的字符串进行解码。 2.unescape(string) -> string 被解码后的一个副本。 可对通过 escape() 编码的字符串进行解码。 string 必需。要解码或反转义的字符串。 说明: 1.ECMAScript v3 已从标准中删除了 unescape() 函数,并反对使用它, 因此应该用 decodeURI() 和 decodeURIComponent() 取而代之。 * */ console.log(escape("Need tips? Visit RUNOOB!")); // Need%20tips%3F%20Visit%20RUNOOB%21 console.log(unescape('Need%20tips%3F%20Visit%20RUNOOB%21')); // Need tips? Visit RUNOOB! console.log(escape("?!=()#%&")); // %3F%21%3D%28%29%23%25%26 </script> </body> </html>
js escape()_unescape().html
最新推荐文章于 2025-03-03 15:43:35 发布