encodeURI 不会编码以下特殊字符A-Z a-z 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) # let uri = "?qry=M & L"console.log(encodeURI(uri))因此您可以使用 encodeURIComponent ,这将对除这些字符之外的所有字符进行编码A-Z a-z 0-9 - _ . ! ~ * ' ( ) let uri = "?qry=M & L"console.log(encodeURIComponent(uri))I am encoding the following string in javascriptencodeURI = "?qry=M & L";This give me an outputqry=m%20&%20lSo the "&" from M & L is not getting encoded. What should i do? 解决方案 ReferenceencodeURI will not encode following special charcatersA-Z a-z 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #let uri = "?qry=M & L"console.log(encodeURI(uri))So you can use encodeURIComponent ,this will encode all the characters except theseA-Z a-z 0-9 - _ . ! ~ * ' ( )let uri = "?qry=M & L"console.log(encodeURIComponent(uri)) 这篇关于用javascript编码url而不编码&的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-11 11:40