javascript get href.replace 中间字符串 [英] javascript get href.replace the middle string

查看:20
本文介绍了javascript get href.replace 中间字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我想输出为 httplocalhost808052773890547536128

我已经在 javascript 中试过了

i have tried this in javascript

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

它给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.

这篇关于javascript get href.replace 中间字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆