假设我有这个网址:
http://www.example.com/#articles/123456/
我想获取JS
中#
后面的值。
分别是:文章和123456
我能够使用以下方法获取整个字符串:
var type = window.location.hash.substr(1);
结果是:articles/123456/
有没有办法单独获取每个变量?
提前致谢。
最佳答案
var type = window.location.hash.substr(1);
var parts = type.split("/");
console.log(parts[0]) // -> articles
console.log(parts[1]) // -> 123456
关于javascript - 如何获取哈希符号后的多个 URL 变量的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31625861/