ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
在URL或URI中,有一些字符是具有特殊含义的。如果我们想“转义”这些字符,就可以去调用函数encodeURI()或encodeURIComponent()。 前者会返回一个可用的URL,而后者则会认为我们所传递的仅仅是URL的一部分。 例如: ``` >>> var url = 'http://find35.com/index.php?s =/Home/Article/index/id/191.html'; undefined >>> encodeURI(url); http://find35.com/index.php?s%20=/Home/Article/index/id/191.html >>> encodeURIComponent(url); http%3A%2F%2Ffind35.com%2Findex.php%3Fs%20%3D%2FHome%2FArticle%2Findex%2Fid%2F191.html ``` encodeURI()对应的解码是decodeURI() encodeURIComponent()对应的解码是decodeURIComponent()