我想让一个 div 的内容在单击另一个 div 时显示出来。但我试过这个:
function loadFishContent() {
if (div is clicked) {
document.getElementById('fish').style.display = "block";
document.getElementById('dogs').style.display = "none";
document.getElementById('cats').style.display = "none";
}
};
我努力了:
if (document.getElementByID('menu-fish') == true) {
//do action
}
但是该操作适用于我单击的所有 div。
我的html是:
<div id="menu-fish" onclick="loadFishContent()"> Fish </div>
<div id="menu-dogs" onclick="loadDogsContent()"> Dogs </div>
<div id="menu-cats" onclick="loadCatsContent()"> Cats </div>
<div id="content">
<div id="fish">
<h2> Fish </h2>
<img src="fish.jpg"/>
<p> Information about fish in the store goes here.</p>
</div>
<div id="dogs">
<h2> Dogs </h2>
<img src="dog.jpg" />
<p> Information about dogs in the store go here.</p>
</div>
<div id="cats">
<h2> Cats </h2>
<img src="cat.jpg" />
<p> Information about cats in the store go here.</p>
</div>
</div>
问题是,我如何定位在 if 条件下单击的 div?