js使用encodeURIComponent实现PHP的rawurlencode 发表于 2020-06-11 | 更新于 2023-01-11 js使用encodeURIComponent实现PHP的rawurlencode1234567891011121314function rawurlencode(str = "") { const replaceList = [ { reg: /!/g, value: '%21' }, { reg: /\*/g, value: '%2A' }, { reg: /\(/g, value: '%28' }, { reg: /\)/g, value: '%29' }, { reg: /'/g, value: '%21' }, ]; let resStr = encodeURIComponent(str); replaceList.forEach(({ reg, value }) => { resStr = resStr.replace(reg, value); }); return resStr;}