简体   繁体   English

javascript get href.replace 中间字符串

[英]javascript get href.replace the middle string

my url is http://localhost:8080/?usrType=t#52773890547536126我的网址是http://localhost:8080/?usrType=t#52773890547536126

i want output as httplocalhost808052773890547536128我想输出为httplocalhost808052773890547536128

i have tried this in javascript我在javascript中试过这个

config.channel = config.channel || location.href.replace(/\/|:|#|%|\.|\[|\]/g,'');

it gives httplocalhost8080?usrType=t52773890547536126它给httplocalhost8080?usrType=t52773890547536126

You need to replace everything between ?你需要更换之间的一切? and # in addition to removing all those special characters.#除了删除所有这些特殊字符。

config.channel = config.channel || location.href.replace(/\?.*?#|[\/:#%.\[\]]/g,'');

You can use the character set [\\/:#%.\\[\\]] instead of all those single-character alternatives.您可以使用字符集[\\/:#%.\\[\\]]代替所有这些单字符替代项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM