jquery:嵌套标签和悬停()在 IE 中不起作用
我有这样的结构:
<div id="container">
<span>
<span></span>
</span>
<span>
<span></span>
</span>
</div>
我需要捕获容器的 mouseout 事件,所以我让 jquery 这样做:
$("#container").hover('',function(){
alert("Out");
});
在 Firefox / Opera 中,它仅在离开 div 时触发 mouseout 函数 (我多么想要它)。
在 IE 中,它会在鼠标点击的 div 内的每个 *-Tag 处触发 mouseout 函数。 (*也许重要的是,span 标签也有 mouseover 和 out 事件)
有人知道如何解决这个问题吗? (嵌套结构无法更改,因为布局复杂)
thx4任何想法!
i have a construction like this:
<div id="container">
<span>
<span></span>
</span>
<span>
<span></span>
</span>
</div>
i need to catch the mouseout event of the container, so i made jquery do this:
$("#container").hover('',function(){
alert("Out");
});
In Firefox / Opera, it only fires the mouseout-function when leaving the div
(how I want it).
In IE it fires the mouseout-function at every *-Tag inside of the div the mouse hits.
(*maybe important is, that the span tags have also mouseover and out events)
Anyone has an idea how to solve this?
(The nested structure cant be changed because a complex layout)
thx4 any ideas!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
@evelio:它不起作用,id始终是“容器”
我如何解决它(到目前为止......):
无论你相信与否,container-div的属性background-color必须设置为一种颜色。
我仍然对这个事实感到非常震惊,但我尝试了几次,只有CSS中的背景颜色属性决定了它的工作与否。
并且:颜色 #000000 不起作用,任何其他颜色都起作用,包括“白色”
@evelio: it didnt work, the id was always "container"
how i solved it (so far...):
believe it or not, the attribute background-color of the container-div had to be set in a color.
im still quite shocked of this fact but i tryed it several times and its only the background-color attribute in the css that makes it work or not.
and: the color #000000 does not work, any other color does, including "white"
另请阅读:事件冒泡和捕获
also read: Event bubbling and capturing
试试这个
至于IE,抵制这个蹩脚的浏览器,并在博客上讲述它的绝望,直到你的手指麻木。该浏览器导致网页设计师的时间比应有的时间少了 33% 左右。尽你所能杀死它。
try this
As for IE, boycott the crappy browser and make blogs about its sheer hopelessness until your fingers go numb. That browser is responsible for web designers' time being worth about 33% less than it should be. Just kill it any way you can.
解决这个问题的方法是添加一个 1px 透明 png 作为背景。
请参阅: IE8:Div 悬停仅当设置背景颜色时才有效,很奇怪,为什么?
The way you can solve it is adding a 1px transparant png as background.
See: IE8: Div hover only works when background color is set, very strange, why?
嗯,我附近没有 IE,但你可以尝试 jQuery mouseout 演示 (以及悬停演示)如果它工作正常似乎是你的代码在其他行中的问题......最后你可以解决它:
Mhhh I don't have IE near but you can try the jQuery mouseout demos (and hover demos) if it works fine seems to be a trouble with your code in some other line... finally you can workaroud it with:
您是否尝试过:
或:
或者更好:
如果您只需要鼠标移出,则没有理由使用悬停功能。
Have you tried:
or:
or better still:
If you only need the mouseout there is no reason to use the hover function.
我在 IE 6、7 和 8 中遇到了类似的问题。Mafka 是对的,必须设置背景颜色才能使其正常工作。如果在“容器”上设置背景颜色不可行,您仍然可以将背景颜色设置为白色并将不透明度设置为 0。
我在绑定之前使用以下 JavaScript 代码完成了此操作jQuery 中的鼠标悬停事件:
I had a similar issue in IE 6, 7, and 8. Mafka is right, the background color has to be set to make it work. If it’s not feasible to set a background color on your “container”, you can still set the background color to white and set the opacity to 0.
I’ve done this with the following JavaScript code before binding the mouseover Event in jQuery: