这是我尝试匹配的网址示例:http://store.mywebsite.com/folder-1/folder-2/item3423434.aspx
我试图匹配的是http://store.mywebsite.com/folder-1,但“folder-1”始终是不同的值。我不知道如何为此编写 if 语句:
示例(伪代码)
if(url contains http://store.mywebsite.com/folder-1)
do this
else if (url contains http://store.mywebsite.com/folder-2)
do something else
Run Code Online (Sandbox Code Playgroud)
ETC
为了让事情变得非常简单......
if(location.pathname.indexOf("folder-1") != -1)
{
//do things for "folder-1"
}
Run Code Online (Sandbox Code Playgroud)
如果值“folder-1”可能出现在字符串的其他部分,这可能会给您带来误报。如果您已经确定情况并非如此,那么提供的示例应该足够了。