Javascript 扩展encodeURIComponent,以便从编码中跳过一些值
有一个URL,如Javascript 扩展encodeURIComponent,以便从编码中跳过一些值,javascript,angularjs,Javascript,Angularjs,有一个URL,如 var url = `damen/hosen-roecke/7%2F8-laenge` 编码时 encodeURIComponent(url)它返回damen%2fosen roecke%2F7%252F8 laenge 但是我需要从已经编码过一次的编码中跳过这个特定部分7%2F8。 所以我猜如何重写encodeURIComponent,这样它就可以跳过这个特殊的格式'7%2F8' 因此,它可以像编码后一样工作,它应该返回damen%2fosen-roecke%2F7%2F8
var url = `damen/hosen-roecke/7%2F8-laenge`
编码时
encodeURIComponent(url)
它返回damen%2fosen roecke%2F7%252F8 laenge
但是我需要从已经编码过一次的编码中跳过这个特定部分7%2F8
。
所以我猜如何重写encodeURIComponent
,这样它就可以跳过这个特殊的格式'7%2F8'
因此,它可以像编码后一样工作,它应该返回
damen%2fosen-roecke%2F7%2F8-laenge
,因为字符串包含已编码的部分,所以首先对字符串进行解码,然后再次编码
encodeURIComponent(decodeURIComponent(url)) // "damen%2Fhosen-roecke%2F7%2F8-laenge"
var url=`damen/hosen-roecke/7%2F8-laenge`;
document.body.innerHTML=encodeURIComponent(解码UriComponent(url))编码>由于字符串包含已编码的部分,请先对字符串进行解码,然后再次编码
encodeURIComponent(decodeURIComponent(url)) // "damen%2Fhosen-roecke%2F7%2F8-laenge"
var url=`damen/hosen-roecke/7%2F8-laenge`;
document.body.innerHTML=encodeURIComponent(解码UriComponent(url))代码>是的,很好。但我的主要问题是,是的,这很好。但我的主要问题是解释请问题是:使用AngularJS不应该排除使用vanilla js。@Tushar我从一个api得到一个url段塞,它的格式已经编码好了。但当我使用angulars$location.url(url)时,它在浏览器中会自动删除。当我使用$location.path(url)时,再次对其进行编码。奇怪的是,当我传递一个没有任何编码的纯url时,它在浏览器中没有变化。因此,我考虑对已编码的url使用$location.path(),并对encodeURIcomponent进行过度查看,例如跳过“7%2F8”。请解释问题是:使用AngularJS不应排除使用vanilla js。@Tushar从api中获得一个已编码格式的url段塞。但当我使用angulars$location.url(url)时,它在浏览器中会自动删除。当我使用$location.path(url)时,再次对其进行编码。奇怪的是,当我传递一个没有任何编码的纯url时,它在浏览器中没有变化。因此,我考虑对已经编码的url使用$location.path(),并对encodeURIcomponent进行过度查看,例如跳过“7%2F8”。