我的 javascript 自定义选择的 onmouseout 问题
我已经使用 javascript 创建了一个自定义选择,如下所述: http://v2.easy-designs .net/articles/replaceSelect/
关键思想是 select 是由包含两个(在我的例子中)的 组成的
ulNode.onmouseout = function() {
if (ulNode.className.indexOf('selectOpen') !- -1){
选择我(li[0]);
}
}
即,如果鼠标离开 ul,并且 ul 打开,则应选择第一个元素。这工作正常,但是当我在 li 之间移动鼠标时,即使我没有离开包含的 ul,这个函数也会被调用。知道为什么会发生这种情况吗?
提前致谢!
I've created a custom select using javascript as described here: http://v2.easy-designs.net/articles/replaceSelect/
The key idea is that the select is built of a containing two (in my case)
ulNode.onmouseout = function() {
if (ulNode.className.indexOf('selectOpen') !- -1){
selectMe(li[0]);
}
}
i.e. if the mouse leaves the ul, and the ul is open, the first element should be selected. This works fine, but this function gets called when I move my mouse between li's, even though I haven't left the containing ul. Any ideas why that might happen?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于这种情况,
mouseover
和mouseout
是错误的事件之王。当具有 mouseout 事件的元素内有其他元素时,它们会被频繁触发。你需要类似mouseleave
和mouseenter
jQuery 中的Mouseleave
mouseover
andmouseout
are wrong king of events for this case. They are fired way too often when you have other elements inside the element that has mouseout event. You need something likemouseleave
andmouseenter
Mouseleave in jQuery
尝试在 mouseout 事件之前实现一些延迟,如下所示:
这有望处理不需要的原子事件。
请注意
(B)
中的范围。Try implementing some delay before the mouseout event like this:
This hopefully handles the nonwanted atomic events.
Careful with the scope in
(B)
.