我试图根据正在查看的页面突出显示导航按钮(在菜单中)。以下是我迄今为止:突出显示基于位置的按钮
var loca = String(document.location.href);
// Get document location and specific page.
if (loca) {
if(loca.search(RegExp("((/[\w]*)\.php)")) != -1) {
activate(loca.match(RegExp("((/[\w]*)\.php)").split("/").join("")));
} else {
activate("home");
}
}
// Activate a button
function activate(bName) {
$(".button[name=" + bName + "]").css({
"border-left": "1px solid white",
"border-right": "1px solid white"
});
}
我希望发生的是:页面的
- 获取URL
- 获取页面的特定文件名,如果没有找到,则我们在主页上。
- 使用jQuery,我尝试查找按钮的名称,如果名称与文件名匹配,则突出显示它。
事情是,这只突出显示“主页”按钮。我究竟做错了什么?另外,如果您对如何更好地完成此任务有任何建议,请让我知道!
我也建议做一个CSS类,然后添加/删除类,而不是硬编码的值。 – 2011-03-15 18:53:13
@尼克:我同意你的看法,我以前也是这样,但我仍然有同样的问题。 ;) – Shaz 2011-03-15 20:11:30