gpt4 book ai didi

Javascript 菜单高亮切换器

转载 作者:行者123 更新时间:2023-11-28 18:25:37 25 4
gpt4 key购买 nike

我正在尝试创建一个页面,它只是一个包含不同 div 的页面,这些 div 在未被选中时会隐藏。

Currently i'm having some problem with the menu buttons, i want the selected page to be highlighted, then when another tab is selected, the other tab is highlighted instead.

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

因此,如果它在主页 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)"

但是好像不行,有什么帮助吗?或者其他更简单的建议 :)?

最佳答案

使用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')"

关于Javascript 菜单高亮切换器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15852668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com