gpt4 book ai didi

javascript - PHP Javascript 包含 URL 中的所有页面

转载 作者:行者123 更新时间:2023-11-28 04:57:01 26 4
gpt4 key购买 nike

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

if(document.URL.indexOf("http://localhost/folder/") == 0) {
// We are in a page in or under folder
}

关于javascript - PHP Javascript 包含 URL 中的所有页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21080861/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com