在mouseover和mouseout上显示隐藏div

问题描述:

<script type="text/javascript">
function show_sidebar()
{
document.getElementById('sidebar').style.visibility="visible";
}

function hide_sidebar()
{
document.getElementById('sidebar').style.visibility="hidden";
}
</script>

<img src="images/cart.jpg" width="80px" height="30px" onMouseOver="show_sidebar()"     onMouseOut="hide_sidebar()">

<div id="sidebar">some thing</div>

这是我在mouseover和mouseout上显示和隐藏侧边栏div的代码。它的工作,但我想要的是,当我有鼠标悬停在图像上,侧边栏div显示,我想边栏div也显示时,鼠标是侧边栏。如何做到这一点。

This is my code for showing and hiding sidebar div on mouseover and mouseout. Its working but i want is when i have mouseover on image, sidebar div is shown and i want sidebar div to be shown also when mouse is over sidebar. How can u do it.

将事件处理程序移动到一个包装div来完成你想要的功能。
$ b

Move the eventhandlers to a wrapper div to accomplish what you want.

<div id="wrapper" onMouseOver="show_sidebar()" onMouseOut="hide_sidebar()">
  <img src="images/cart.jpg" width="80px" height="30px">
  <div id="sidebar">some thing</div>
</div>