我有一张图像,我想在单击图像时在其上添加文本。我将 css 显示属性应用为 none,然后单击将其更改为 block。现在再次单击“我想将显示更改为无”。我怎样才能做到这一点?
js:-
function showTerms(data){
document.getElementById(data).style.display = 'block';
}
html:-
<div style="display: none;" id="text1111" class="offer_text size-12">
<div class="TC">
<div class="condition">Terms & Condition</div>
</div>
<p></p>
<div><br></div>
<div>- The coupon code is valid for one time use per user account.<br></div>
<p></p>
最佳答案
您可以使用切换功能来实现此目的,如下所示:
function toggleTerms(data){
document.getElementById(data).style.display = (document.getElementById(data).style.display == 'block' ? 'none': 'block');
}
关于javascript - 使用javascript单击同一按钮时更改两种样式之间的css值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37224699/