我在 JS 文件中使用以下代码:
var match = window.location.search.match(/(\d*)/);
this.room = (match) ? decodeURIComponent(match) : 0;
我正在尝试从我的 URL 中获取数字。例如,在 www.myurl.com/streams228
中,我只想获取 228
。
我遇到的问题是它只返回 %2
,没有其他任何内容,或者 0
。
最佳答案
尝试以下操作:
var url ="www.myurl.com/streams228"
var match = url.match(/([\d]+)/g);
console.log(match[0]);
关于javascript - 无法从 window.location.search 获取号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47685460/