Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
包含URL中所有页面的PHP Javascript_Javascript_Php_Jquery_Html_Accordion - Fatal编程技术网

包含URL中所有页面的PHP Javascript

包含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

我有一个使用页面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 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
}