我只想返回我的 URL 的数字。目前我使用:
alert(document.URL);
获取整个 URL。但是有没有其他简单的解决方案可以只从我的 URL 中获取 ID 号呢?我也在这个项目中使用了 jQuery 和 PHP。
最佳答案
var numbers = document.URL.match(/\d+/g)
将返回 URL 中的所有数字(例如对于此线程) document.URL.match(/\d+/g)
=> ["19570840"]
关于javascript - 只从 URL 中获取数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19570840/