2013-04-06 23 views
1

我正在尝试创建一个页面,它只是一个页面,其中不同的div在未选中时隐藏。Javascript菜单高亮切换器

目前我遇到菜单按钮出现问题,我希望选定的页面高亮显示,然后选择另一个选项卡时,另一个选项卡将突出显示。

说 主页,关于我们,联系我们

所以,如果在家里DIV,主页选项卡被突出显示,但如果它的关于我们的div中,关于我们高亮显示。我想使用纯CSS,但搜索后没有任何结果,所以我必须坚持使用JavaScript。

这是我的代码

function Switcher(a,b,c,d,e){ 
document.getElementById('button1').style.background=a; 
document.getElementById('button2').style.background=b; 
document.getElementById('button3').style.background=c; 
document.getElementById('button4').style.background=d; 
document.getElementById('button5').style.background=e; 
} 

与一个onClick功能

onClick="Switcher(#c5e043,#241009,#241009,#241009,#241009)" 

,但它似乎没有工作,任何帮助吗?或其他更简单的建议:)?

回答

1

,而不是使用背景backgroundColor

function Switcher(a,b,c,d,e){ 
    document.getElementById('button1').style.backgroundColor = a; 
    document.getElementById('button2').style.backgroundColor = b; 
    document.getElementById('button3').style.backgroundColor = c; 
    document.getElementById('button4').style.backgroundColor = d; 
    document.getElementById('button5').style.backgroundColor = e; 
} 

而且传递的参数字符串:

onClick="Switcher('#c5e043', '#241009', '#241009', '#241009', '#241009')" 
+0

噢,总是缺少次要的细节:d多谢!还是一个新的编码器:) – Crays 2013-04-06 15:42:36

0

或者其他简单的建议:)?

脚本:

function Switcher(Colors) 
    { 
    var Count=1; 

Colors.split(",").forEach(function(xColor) { document.getElementById('button' + Count).style.background = xColor; 
Count +=1; }); 

} 

的onclick:

onClick="Switcher("#c5e043,#241009,#241009,#241009,#241009")"