子元素的鼠标悬停时调用父 Div 的鼠标移出函数
有以下 HTML
<div id='divContainer1' onmouseover=ShowEditDiv(1) onmouseout=HideEditDiv(1) class='divClcContainer'>
<div id='divSlNo1'>1</div>
<div id='divItem1'>This is content</div>
<div id='divEditLink1'></div>
</div>
<div id='divContainer2' onmouseover=ShowEditDiv(2) onmouseout=HideEditDiv(2) class='divClcContainer'>
<div id='divSlNo2'>2</div>
<div id='divItem2'>This is content2</div>
<div id='divEditLink2'></div>
</div>
我的页面和 javascript 中
function ShowEditDiv(divId)
{
$("#divEditLink" + divId).html("<a href=\"javascript:Edit(divId)\"><img src='edit_icon.gif' alt='Edit' title='Edit' /></a>").addClass("divEdit");
}
function HideEditDiv(divId)
{
$("#divEdit" + divId).empty().addClass('divEdit');
}
我的要求是当用户将鼠标放在主 div 上时显示编辑链接。现在它工作正常。但是当我将鼠标放在保存编辑图像/链接的 div 上时,它消失了。我发现当我将鼠标放在编辑 div 上时,父 div 的 mouseout 函数被调用。任何人都可以帮我解决这个问题吗?
I have the below HTML in my page
<div id='divContainer1' onmouseover=ShowEditDiv(1) onmouseout=HideEditDiv(1) class='divClcContainer'>
<div id='divSlNo1'>1</div>
<div id='divItem1'>This is content</div>
<div id='divEditLink1'></div>
</div>
<div id='divContainer2' onmouseover=ShowEditDiv(2) onmouseout=HideEditDiv(2) class='divClcContainer'>
<div id='divSlNo2'>2</div>
<div id='divItem2'>This is content2</div>
<div id='divEditLink2'></div>
</div>
and in my javascript
function ShowEditDiv(divId)
{
$("#divEditLink" + divId).html("<a href=\"javascript:Edit(divId)\"><img src='edit_icon.gif' alt='Edit' title='Edit' /></a>").addClass("divEdit");
}
function HideEditDiv(divId)
{
$("#divEdit" + divId).empty().addClass('divEdit');
}
My requirement is to show an edit link when user place his mouse over the master div. Now its working fine.But when i place mouse over the div which holds the edit image/link, it is disappearing. I found that when i place mouse over the edit div, the mouseout function of parent div is getting called. Can any one help me to solve this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决此错误的方法是使用 mouseenter 和 mouseleave 事件,而不是 mouseover 和 mouseout。
有关此内容的更多信息,请参见此链接
http:// /jquery-howto.blogspot.com/2009/04/problems-with-jquery-mouseover-mouseout.html
The solution to this error is to use mouseenter and mouseleave events instead of mouseover and mouseout.
More information on this present in this link
http://jquery-howto.blogspot.com/2009/04/problems-with-jquery-mouseover-mouseout.html
使用
在子元素中 stopPropagation功能。
Use
stopPropagation in child elements function.