目前我知道的js获取携带参数的url的方式是window.location.search
但是假如说有个链接是 www.xxxxxx.com?aaa=bbb&ccc=ddd#ok
取得的就是?aaa=bbb&ccc=ddd#ok我不想要这个#后面的这个hash值,能去掉不,还是必须要用正则才能去掉?
location 对象有一个 hash 属性,存储着 URL 中以 # 开头的字符串,所以不一定要用正则替换,直接匹配替换也可以:
hash
var nohash = window.location.href.replace(window.location.hash, '');
参考:http://www.w3school.com.cn/js...
2.1m questions
2.1m answers
60 comments
56.9k users