gpt4 book ai didi

单击 标记时隐藏/显示给定元素的 JavaScript 代码

转载 作者:行者123 更新时间:2023-12-03 10:50:25 24 4
gpt4 key购买 nike

是否可以单击相同的链接来隐藏和显示下面的 coy?这是我到目前为止所拥有的。我能够创建一个 JavaScript 来显示副本,但我不知道如何单击相同的链接来隐藏它。我有html的基本知识。这是我正在使用的代码

<p>
<strong>
<a href="javascript:;" onclick="document.getElementById('text1').style.display='block';">
Gifts that Don't Impact your Lifestyle
</a>
</strong>
<div id="text1" style="display: none; margin-top: 2px;">
There are many ways to give a gift to without impacting your lifestyle.
</div>
</p>
<p>
<strong>
<a href="javascript:;" onclick="document.getElementById('text2').style.display='block';">
Gifts that Increase your Income
</a>
</strong>
</p>
<div id="text2" style="display: none;">
You can enhance your income while supporting a Charitable Gift Annuity or Charitable Remainder Trust.
</div>
<p>
<strong>
<a href="javascript:;" onclick="document.getElementById('text3').style.display='block';">
Gifts that Provide for your Heirs
</a>
</strong>
<div id="text3" style="display: none;">
You can pass assets to your family on a tax favorable basis while providing immediate support.
</div>
</p>

最佳答案

是的,

<p><strong><a href="javascript:;" onclick="document.getElementById('text1').style.display === 'block' ? document.getElementById('text1').style.display = 'none': document.getElementById('text1').style.display = 'block';">Gifts that Don't Impact your Lifestyle</a></strong></p><div id="text1" style="display:none; margin-top:2px;">There are many ways to give a gift to without impacting your lifestyle.</div>

<p><strong><a href="javascript:;" onclick="document.getElementById('text2').style.display === 'block' ? document.getElementById('text2').style.display = 'none': document.getElementById('text2').style.display = 'block'">Gifts that Increase your Income</a></strong></p><div id="text2" style="display:none;">You can enhance your income while supporting a Charitable Gift Annuity or Charitable Remainder Trust.</div>

<p><strong><a href="javascript:;" onclick="document.getElementById('text3').style.display === 'block' ? document.getElementById('text3').style.display = 'none': document.getElementById('text3').style.display = 'block'">Gifts that Provide for your Heirs</a></strong>
<div id="text3" style="display:none;">You can pass assets to your family on a tax favorable basis while providing immediate support.</div></p>

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