包含URL中所有页面的PHP Javascript
我有一个使用页面url的脚本。根据此URL,将以不同方式加载导航菜单。例如在主页上包含URL中所有页面的PHP Javascript,javascript,php,jquery,html,accordion,Javascript,Php,Jquery,Html,Accordion,我有一个使用页面url的脚本。根据此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
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';
}
提前感谢您可以使用以下索引:
您可以使用indexOf:
这应该会有所帮助
这将有助于甚至更好地使用indexOfyourString==0来确保它真正以给定的字符串开始。这非常有效。我知道这是一个简单的解决方案,但我不太知道语法和如何在谷歌上搜索单词。谢谢各位。最好使用indexOfyourString==0来确保它真正从给定的字符串开始。这非常有效。我知道这是一个简单的解决方案,但我不太知道语法和如何在谷歌上搜索单词。谢谢各位。我们将尽快接受答复
if(document.URL.indexOf("http://localhost/folder/") == 0) {
// We are in a page in or under folder
}
if(location.href.indexOf("http://localhost/folder/") == 0) {
// We are in a page in or under folder
}