我想在我的网站页面上有一个标准菜单。我正在使用包含文件,如下所示:
<div class="header box">
<ul class="nav box">
<li class="current" id="home"><a href="index.php" onclick="current('home')">Home</a></li>
<li class="" id="onlineSchedule"><a href="onlineSchedule.php" onclick="current(this)">Online Schedule</a></li>
<li class="" id="partners"><a href="partners.php" onclick="current(this)">Partners/Centers</a></li>
<li class="" id="services"><a href="services.php" onclick="current(this)">Services</a></li>
<li class="" id="products"><a href="products.php" onclick="current(this)">Products</a></li>
<li class="" id="newsHighlights"><a href="newsHighlights.php" onclick="current(this)">News/Highlights</a></li>
<li class="" id="signup"><a href="signup.php" onclick="current(this)">Sign Up!</a></li>
<li class="" id="feedback"><a href="feedback.php" onclick="current(this)">Feedback</a></li>
</ul>
但是我希望每当我单击不同的页面时该类都会更改,因为“当前”类会突出显示菜单中的链接。我该怎么做呢?我在下面尝试了 Javascript 作为 shwon 但它不起作用......提前谢谢
function current(page)
{
//alert(page);
document.getElementById("home").setAttribute("class", "");
document.getElementById("onlineSchedule").setAttribute("class", "");
document.getElementById("partners").setAttribute("class", "");
document.getElementById("services").setAttribute("class", "");
document.getElementById("products").setAttribute("class", "");
document.getElementById("newsHighlights").setAttribute("class", "");
document.getElementById("signup").setAttribute("class", "");
document.getElementById("feedback").setAttribute("class", "");
document.getElementById(page).className += "current";
var temp = document.getElementById("home").getAttribute("class");
alert(temp);
}