简体   繁体   English

鼠标悬停时JavaScript显示子div

[英]JavaScript display child div on mouseover

I have the following HTML: 我有以下HTML:

<div id="wrapper">
    <div onmouseover="displayDiv()">  <div id="thisIsTheDivToDisplay"></div   </div>
    <div onmouseover="displayDiv()">  <div id="thisIsTheDivToDisplay"></div>  </div>
    <div onmouseover="displayDiv()">  <div id="thisIsTheDivToDisplay"></div>  </div>
    <div onmouseover="displayDiv()">  <div id="thisIsTheDivToDisplay"></div>  </div>
</div>

I want to display the div inside, when I mouseover it's parent div . 我想要显示的div里面,当我mouseover它的parent div But I'cant use ID's, because the number of div's is random (depends on values in database). 但是我不能使用ID,因为div的数目是随机的(取决于数据库中的值)。 Is there any way in JavaScript to display that only child div (depending on div I mouseover)? JavaScript中有什么方法可以显示唯一的子div (取决于我将鼠标悬停在div )?

why you need to use js? 为什么需要使用js? it can be solved via css. 可以通过CSS解决。 here is fiddle with working example 这是摆弄工作的例子

<div class="lol">
    <div>lol</div>
</div>

<div class="lol">
    <div>lol</div>
</div>

<div class="lol">
    <div>lol</div>
</div>


.lol{width:100px;height:100px; background:red;margin:10px}
.lol div{display:none}
.lol:hover div{display:block} 

http://jsfiddle.net/kpblc/4Vfra/ http://jsfiddle.net/kpblc/4Vfra/

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

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