I'm trying to compare URL with javascript the current url is:
http://domain/products?save&step&id=287
I used window.location.search, it rendered:
?save&step&id=287
I need to know how to compare URL with any number like this pseudocode, I used (any_number) as example of random number, it doesn't need to match equal number since I had no idea which is properly method.
var prod_url = window.location.search;
if(prod_url == "?save&step&id="+(any_number){
alert("URL is matched");
}
I'm open with all suggestions, any method with excepted result is welcome.
答案 0 :(得分:1)
答案 1 :(得分:1)
您可以使用正则表达式:
所以你的if语句应该是这样的:
if ((/\\?save&step&id=\d/).test(prod_url)) {
alert("URL is matched");
}
这应该适用于任何数字。
答案 2 :(得分:1)
请试试这个:
var prod_url = "?save&step&id=12345";
if (/\?save\&step\&id=[0-9]+$/.test(prod_url)) {
alert("URL is matched");
}