首页 > 解决方案 > encodeURIComponent() 小写

问题描述

在 JavaScript 中,我想使用encodeURIComponent(),但输出是大写的。

console.log(encodeURIComponent("[Abcd123]"));
//returns %5BAbcd123%5D

我想要一个小写的结果,比如

%5bAbcd123%5d

可能吗?

标签: javascriptjqueryencodeuricomponent

解决方案


您可以使用正则表达式将后面的两个字符转换%为小写。

console.log(encodeURIComponent("[Abcd123]").replace(/%../g,  match => match.toLowerCase()));


推荐阅读