gpt4 book ai didi

javascript - 我想关闭一个已经打开的 div 并在我单击链接时显示另一个

转载 作者:太空宇宙 更新时间:2023-11-04 04:02:10 26 4
gpt4 key购买 nike

我有这个功能,当我点击一个链接时打开和关闭一个 div,并在下一次点击同一个链接时再次关闭它。它工作得很好。

但现在我想添加另一个 div,它在页面加载时显示,但当我单击用于打开第一个 div 的相同链接时关闭。可以修复吗?

我已经搜索了模拟功能,但我还没有找到一个可以完成这项工作的。

<SCRIPT LANGUAGE="JavaScript">
function lunchboxOpen(lunchID) {
document.getElementById('lunch_' + lunchID).style.display = "block";
document.getElementById('clasp_' + lunchID).innerHTML="<a href=\"javascript:lunchboxClose('" + lunchID + "');\">...show more...</a>";
}
function lunchboxClose(lunchID) {
document.getElementById('lunch_' + lunchID).style.display = "none";
document.getElementById('clasp_' + lunchID).innerHTML="<a href=\"javascript:lunchboxOpen('" + lunchID + "');\">...show more...</a>";
}
</script>

<style type="text/css">
.clasp{text-align:center;}
.lunchbox{display:none;}
</style>

<div id="clasp_1" class="clasp"><a href="javascript:lunchboxOpen('1');">...show more...</a></div>
<div id="lunch_1" class="lunchbox"> ... my content</div>

<div id="my_new_div">This content should be seen when page loads but hidden after click on the link</div>

最佳答案

将此添加到您的函数中:

document.getElementById('my_new_div').style.display = "none";

关于javascript - 我想关闭一个已经打开的 div 并在我单击链接时显示另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21906413/

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