jQuery:如果 $(this) 或另一个元素模糊,那么
如果当前活动元素 $(this) 或另一个预定义元素(例如:div#tooltip)模糊,我想触发一个函数。但到目前为止我还没有找到如何做到这一点。我尝试过:
$(this).add('div#tooltip').live('blur', function(){
$('div#tooltip').hide();
});
例如,假设 $(this) 是一个输入字段,预定义的第二个元素将是一个工具提示 div,并且如果其中之一模糊,我希望工具提示隐藏。
编辑: div#tooltip 包含一个锚点,如果单击它,该锚点不应使 div#tooltip 隐藏。
编辑2: 好的,这是对我的问题的更准确的解释。我有 $.fn.tooltip 函数,我将其应用于具有可变类名和 id 的各种文本输入。因此,该输入只能在函数内引用为$(this)。
其次,我有工具提示 div,它是由函数创建的。该 div 的 ID 为 #tooltip。此工具提示/div 可以包含一些其他元素,例如锚点。
单击输入字段(此)时会自动显示工具提示。一旦关闭,即使输入字段再次获得焦点,也不会再次显示。
我想做的是:
当文本输入失去焦点时,必须删除工具提示 除非如果光标位于工具提示/div 内或单击此 div 内的元素。
有人吗?
I want to trigger a function if either the currently active element $(this) or another predefined element (e.g.: div#tooltip) blurs. However so far I've not found out how to do this. I've tried:
$(this).add('div#tooltip').live('blur', function(){
$('div#tooltip').hide();
});
Imagine that $(this) would be an input field, for example, and the predefined second element would be a tooltip div and that I would want the tooltip to hide if one of those blurs.
EDIT:
The div#tooltip contains an anchor, which should not make the div#tooltip hide if it's being clicked.
EDIT 2:
Okay, here is a more accurate explanation of my problem. I've got the $.fn.tooltip function which I apply to various text-inputs which have variable class names and id's. Therefore, this input can only be referred to as $(this) within the function.
Secondly I have the tooltip div, which is created by the function. This div goes by the ID #tooltip. This tooltip / div can contain some other elements such as anchors.
The tooltip is shown automatically when the input-field (this) is clicked. Once it's closed it won't be shown again, even if the input-field will be focused again.
What I'm trying to do is:
The tooltip must be removed when the text-input loses it's focus
EXCEPT if the cursor is within the tooltip / div or if an element within this div is being clicked.
Anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样:http://jsfiddle.net/uu3zX/7/
HTML:
JavaScript:
更新
添加了替代解决方案以满足使用
this
的 OP 要求Like this: http://jsfiddle.net/uu3zX/7/
HTML:
JavaScript:
UPDATE
Added alternative solution to fit OP requriment to use
this
借用 IntoTheVoid 的小提琴:您应该将输入和工具提示包装在容器 div(或其他一些容器元素)中,以在一行中执行此操作:
Borrowing from IntoTheVoid's fiddle: You should wrap the input and the tooltip in a container div (or some other container element) to do this in one line:
http://jsfiddle.net/mblase75/uu3zX/5/