我正在尝试将 URL 与 javascript 进行比较,当前 url 是:
http://domain/products?save&step&id=287
我使用了window.location.search,它呈现:
?save&step&id=287
我需要知道如何将 URL 与任何数字(如这个伪代码)进行比较,我使用 (any_number) 作为随机数的示例,它不需要匹配相同的数字,因为我不知道哪个是正确的方法。
var prod_url = window.location.search;
if(prod_url == "?save&step&id="+(any_number){
alert("URL is matched");
}
我愿意接受所有建议,欢迎任何具有异常(exception)结果的方法。
最佳答案
请尝试这个:
var prod_url = "?save&step&id=12345";
if (/\?save\&step\&id=[0-9]+$/.test(prod_url)) {
alert("URL is matched");
}
关于javascript - 如何将 URL 与任意数字进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33241787/