如果选择了一条路径,我希望将类添加到菜点。
如果每个站点都是自己的.php/.html文件,那么就很容易了,但是一切都是在one .php文件中进行的,并且所有内容都是通过操作导航的(?action=main,?action=userinformation)。
我正在寻找一种替代方法,通过路径和操作来完成这项工作。
if (location.pathname == "/index.php") {
$("#main1").addClass("mainActive");
} else if (location.pathname == "/index.php?action=other") {
$("#main2").addClass("mainActive");
} 发布于 2013-02-01 14:01:52
location.pathname不包括查询字符串。但是你可以把它和location.search结合起来
var path = location.pathname + location.search;
// "/index.php" + "?action=other"
if(path === "/index.php?action=other") {
// ...
}发布于 2013-02-01 14:03:01
也许你可以用,比如;
var s = location.search;
if (s === "" || s === "?" || s.indexOf("?action=main") > -1)
// main active
else if (s.indexOf("?action=userinformation") > -1)
// userinformation active
// ... and so onhttps://stackoverflow.com/questions/14647909
复制相似问题