我希望创建一个非常简单的功能,即单击菜单选项卡并更改颜色以让您知道您在哪个页面上。我是新手,所以请放轻松...大声笑
/ php头文件中的菜单/
<ul class="tabs" id="tabs">
<li class="selected"><a href="http://bestofthebestent.com/index.php">Home</a></li>
<li class="inactive"><a href="http://bestofthebestent.com/bio.php">Bio</a></li>
<li class="inactive"><a href="http://bestofthebestent.com/photo.php">Photo</a></li>
<li class="inactive"><a href="http://bestofthebestent.com/music.php">Thank</a></li>
<li class="inactive"><a href="http://bestofthebestent.com/contact.php">Contact</a></li>
</ul>
/*This is the JavaScript file*/
window.onload = initPage;
function initPage() {
var tabs = document.getElementById("tabs").getElementsByTagName("li");
for (var i=0; i<tabs.length; i++){
var links = tabs[i];
links.onclick = tabClicked;
}
}
function tabClicked(){
var tabId = this.id;
document.getElementById(tabId).classList.toggle("selected");
var tabs = document.getElementById("tabs").getElementsByTagName("li");
for (var i=0; i < tabs.length; i++){
var currentTab = tabs[i];
if (currentTab.id !== tabId){
currentTab.class = "selected";
} else {
currentTab.class = "inactive";
}
}
}