模糊事件似乎停止了click事件处理程序的工作?我有一个组合框,只有当文本字段有焦点时,选项才会出现. Select 选项链接应该会导致事件发生.
我这里有一个小提琴的例子:http://jsfiddle.net/uXq5p/6/
To reproduce:
- Select 文本框
- Links appear
- Click a link
- 甚至出现模糊,链接消失
- 没有别的事情发生.
预期行为:
On step 5, after blur occurs, the click even should also then fire. How do I make that happen?
UPDATE:
After playing with this for a while, it seems that someone has gone to great lengths to prevent an already-occurred click event from being handled if a blur event makes the clicked element Un-clickable.
For example:
$('#ShippingGroupListWrapper').css('left','-20px');
works just fine, but
$('#ShippingGroupListWrapper').css('left','-2000px');
prevents the click event.
This appears to be a bug in Firefox, since making an element un-clickable should prevent future clicks, but not cancel ones that have already occurred when it could be clicked.
阻止click事件处理的其他事项:
$('#ShippingGroupListWrapper').css('z-index','-20');
$('#ShippingGroupListWrapper').css('display','none');
$('#ShippingGroupListWrapper').css('visibility','hidden');
$('#ShippingGroupListWrapper').css('opacity','.5');
我在这个网站上发现了一些其他问题,它们也有类似的问题.似乎有两种解决方案:
Use a delay. This is bad because it creates a race condition between the hiding and the click event handler. Its also sloppy.
Use the
mousedown
event. But this isn't a great solution either sinceclick
is the correct event for a link. The behavior ofmousedown
is counter-intuitive from a UX perspective, particularly since you can't cancel the click by moving the mouse off the element before releasing the button.
I can think of a few more.
3.Use mouseover
and mouseout
on the link to enable/disable the blur event for the field. This doesn't work with keyboard tabing since the mouse is not involved.
4.最佳解决方案如下所示:
$('#ShippingGroup').blur(function()
{
if($(document.activeElement) == $('.ShippingGroupLinkList'))
return; // The element that now has focus is a link, do nothing
$('#ShippingGroupListWrapper').css('display','none'); // hide it.
}
不幸的是,$(document.activeElement)
似乎总是返回body元素,而不是单击的元素.但如果有可靠的方法来了解.哪个元素现在有焦点或两个焦点,哪个元素在模糊处理程序中导致模糊(而不是哪个元素正在模糊).此外,在模糊之前是否还有其他触发事件(mousedown
除外)?