我有一个使用页面网址的脚本。根据此URL,导航菜单将以不同方式加载。例如,在主页上,
if(document.URL=="http://localhost/index.php")
{
//Adjust the menu for the home page;
}
但是,如果您位于下方“文件夹”中的任何页面上,则应以不同方式调整菜单。
if(document.URL=="http://localhost/folder/page.php")
{
//Adjust the menu for a page in 'folder';
}
有没有办法可以在此脚本中包含“文件夹”下的所有页面?像:
if(document.URL=="http://localhost/folder/*") //include everything with *
{
//Adjust the menu for every page under 'folder';
}
提前致谢
答案 0 :(得分:3)
您可以使用indexOf
:
if(document.URL.indexOf("http://localhost/folder/") == 0) {
// We are in a page in or under folder
}
答案 1 :(得分:3)
if(location.href.indexOf("http://localhost/folder/") == 0) {
// We are in a page in or under folder
}
这应该有帮助