简体   繁体   English

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

[英]I would like to close one already open div and show another when I click a link

I have this function that opens and closes a div when I click a link, and close it again on the next click on the same link. 我有这个功能,当我点击一个链接时打开和关闭一个div,并在下一次单击同一个链接时再次关闭它。 It works just fine. 它工作得很好。

But now I would like add another div that shows when page load, but close when I click the same link I use to open the first div. 但是现在我想添加另一个显示页面加载时间的div,但是当我点击我用来打开第一个div的相同链接时关闭。 Is that possible to fix? 这有可能解决吗?

I have searched for simular function but I hav not find a one that does the job. 我已经搜索了simular函数,但我没有找到一个能完成这项工作的人。

<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";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM