0

我的网址为:/#profile/7 如何让它从那里获取最后一个数字?我正在寻找从中创建一个 mysql 连接,从某处选择一些东西 WHERE id=':profile' 另外,这种方式是否安全,甚至可以建立连接吗?这就是我所拥有的。

<script>
      var hash = window.location.hash.substring(6);
      alert (hash);
</script>
4

2 回答 2

1

您可以使用正则表达式:

var hash = window.location.hash.match(/\/(\d)/)[1]
于 2013-03-14T13:39:05.180 回答
0

尝试使用split()而不是子字符串:

var parts = window.location.hash.split('/');
var id = parts[parts.length - 1];
于 2013-03-14T13:35:58.953 回答