百分比编码 JavaScript
是否有一个 JavaScript 函数可以接受一个字符串并将其转换为另一个百分比编码的字符串?这样,“This Guy”之类的内容就会变成“This%20Guy”。
谢谢
Is there a javascript function that takes a string and converts it into another string that is percent-encoded? That way something like "This Guy" turns into "This%20Guy".
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
encodeURI
、encodeURIComponent
或escape
对于您的字符串的工作方式相同,但它们在细节上有所不同。encodeURI
仅用于转义 URLencodeURIComponent
也会转义=
和&
escape
对于非 ASCII unicode 符号的工作方式有所不同,如果您需要发送字符串作为请求的一部分,请使用encodeURIComponent
encodeURI
,encodeURIComponent
orescape
will work the same way for your string, but they differ in details.encodeURI
is just for escaping URLsencodeURIComponent
also escapes=
and&
escape
works differently with non-ASCII unicode symbolsif you need to send a string as part of request, use encodeURIComponent
尝试 encodeURIComponent() 或 escape()
Try encodeURIComponent() or escape()
尝试使用
encodeURIComponent()
在需要时使用
decodeURIComponent()
再次解码更多信息请参见
https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_reserved_characters
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
Try this
encodeURIComponent()
Use
decodeURIComponent()
to decode it again when neededMore Info here
https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_reserved_characters
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
是的,这里是
Yes, here is