将鼠标悬停在 div 中以显示 jquery 问题中的文本
我这里有问题。当我的鼠标悬停在 div 上时,div 中会出现一段文本。当鼠标从 div 移出时,文本将消失。然而,我的问题是,当鼠标悬停在出现的文本上时,它会认为它是从 div 中移出的,导致文本消失。我该怎么做才能避免这种情况?我希望只要鼠标位于 div 中,文本就会保留,即使它位于文本上方。谢谢..
<div class="passd"></div>
$('.passd').live("mouseover", function(){
if($(this).children('#passopt').length==0){
$(this).append('<p id="passopt">appear text</p>');
}
});
$('.passd').live("mouseout", function(){
$(this).children('#passopt').remove();
});
I have a problem here. When my mouse hover over a div, a text appear in the div. And when it is on mouseout from the div, the text will disappear. My problem is however when the mouse is over the appeared text, it will treat that it is mouseout from the div, causing the text to disappear. How can i do to avoid that? I want the text to remain as long the mouse is in the div even though it is above the text. Thanks..
<div class="passd"></div>
$('.passd').live("mouseover", function(){
if($(this).children('#passopt').length==0){
$(this).append('<p id="passopt">appear text</p>');
}
});
$('.passd').live("mouseout", function(){
$(this).children('#passopt').remove();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
经过测试,有效:http://jsfiddle.net/xLzdP/
Try this:
Tested, and works: http://jsfiddle.net/xLzdP/
您可以使用 mouseleave 事件来代替...
http://api.jquery.com/mouseleave/
you could use the mouseleave event instead...
http://api.jquery.com/mouseleave/
查看 http://flowplayer.org/tools/tooltip/index.html 查看如果它能做你想做的事...
Check out http://flowplayer.org/tools/tooltip/index.html to see if it can do what you want...
使用 .hover() 可以获得同样多的效果:
You could achieve just as much with using .hover():