jQuery - 如果表单中的元素具有焦点,则不执行队列?

发布于 2024-12-16 15:41:16 字数 338 浏览 7 评论 0原文

我有一个 div 元素,其中包含一个小表单和一个 dhtmlx 数据网格。这个 div 很少使用,所以我使用 jQuery 的 SlideUp 在不需要的时候将其隐藏起来。我在 div 上附加了 mouseenter 和 mouseleave 事件来设置和取消 SlideUp - 这样当鼠标悬停在 div 上时它就不会消失。

然而,当用户单击表单元素或数据网格之一,然后将鼠标移开时,我的问题就出现了。显然用户仍然要求div可见,但是mouseleave事件随后导致div向上滑动!

无论如何,jQuery 中是否有测试 div 中的任何元素是否具有焦点的方法?然后,如果某些东西确实具有焦点,我可以取消 SlideUp 调用。

I have a div element which contains a small form and a dhtmlx datagrid. This div is rarely used so I make use of jQuery's slideUp to hide it out of the way when it isn't needed. I've attached mouseenter and mouseleave events on the div to set up and cancel the slideUp - so that when the mouse is over the div it doesn't disappear.

However, my problem comes in when the user clicks into either one of the form elements or the datagrid and then moves the mouse away. Obviously the user still requires the div to be visible, but the mouseleave event then causes the div to slideUp!

Is there anyway in jQuery of testing whether any element within a div has focus? Then if something does have focus I can cancel the slideUp call.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗失的美好 2024-12-23 15:41:16

查看从 jQuery 1.6+ 添加的 focus 属性

如果您想查找具有焦点的输入,请使用以下命令:

if( $("#mydiv input:focus").length > 0 ) {}

Look at the focus property which is added from jQuery 1.6+

If you want to find the input that has focus use this:

if( $("#mydiv input:focus").length > 0 ) {}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文