因此,我尝试使用 Javascript 函数通过单击事件更改 Accordion 菜单的标题颜色。正如我现在所拥有的那样,颜色会在我第一次点击时改变,但不会在第二次点击时改变。
我的 HTML Accordion 设置:
<div id ="accordion">
<a class="tab" onclick="highlightHead(this, '#2E8AE6')" href="javascript:AccordionControls('headerOne')">Header One</a>
<div id="headerOne" class="tab-content" style="display:none">This is my first header paragraph</div>
<a class="tab" onclick="highlightHead(this, '#2E8AE6')" href="javascript:AccordionControls('headerTwo')">Header Two</a>
<div id="headerTwo" class="tab-content" style="display:none">This is my second header paragraph</div>
</div>
我的 Javascript 函数:
function highlightHead(headerID, color)
{
if (headerID.style.backgroundColor = "#000033") {
headerID.style.backgroundColor = color;
} else {
headerID.style.backgroundColor = "#000033";
}
}
最佳答案
您需要将 === 放在 if 语句中而不是 =
关于javascript - 通过 Javascript 在点击时更改 Accordion 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32763662/