我创建了一个 HTML 片段,如下所示 -
<div id = 'Div1'
style = 'height: 30px; width: 100%; margin: 0; padding: 0; border: 1px solid #7f7f7f; padding-left: 25px; font-size: 15px; color: #666666;
border-top-left-radius: 5px; border-top-right-radius: 5px;
display: flex; flex-direction: row; text-align: left; align-items: center; justify-content: left; position: relative;'>
Header
<div id = 'Div2'
onclick = "{
var GetText = document.getElementById('Div2').innerHTML;
if (GetText == '−') {
document.getElementById('Div1').style.borderBottom = '0px';
document.getElementById('Div3').offsetHeight = 1;
document.getElementById('Div2').innerHTML = '+';
} else {
document.getElementById('Div1').style.borderBottom = '1px';
document.getElementById('Div3').offsetHeight = 'auto';
document.getElementById('Div2').innerHTML = '−';
}
};"
style = 'margin: 0; padding: 0; position: absolute; right: 0; top: 0; height: 30px; width: 30px; color: #999999; cursor: pointer;
display: flex; flex-direction: row; text-align: center; align-items: center; justify-content: center; background-color: rgba(0,0,0,.0);'>
−
</div>
</div>
<div id = 'Div3'
style = 'height: auto; width: 100%; margin: 0; padding: 0; overflow: hidden; border: 1px solid #7f7f7f; border-top: 0px;
border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; '>
<div style = 'height: auto; mim-height: 0px; width: 100%; margin: 0; padding: 0; padding: 12px; font-size: 15px; color: #666666;
text-align: left; '>
Answer
</div>
</div>
我的目标是,如果我单击"-"标志,则底部部分将折叠并且"-"标志将更改为"+"。但是,当我点击"+"时,就会发生相反的情况。
通过我上面的代码,这并没有明显发生。
您能帮我了解出了什么问题吗?
Helenr
偶然的你
汪汪一只猫
相关分类