我有一个小的jquery脚本:
$('.field').blur(function() {
$(this).next().children().hide();
});隐藏的子项包含一些链接。这使得无法单击链接(因为它们被隐藏)。对此有什么合适的解决方案?
这是我得到的最接近的结果:
$('.field').blur(function() {
$('*').not('.adress').click(function(e) {
foo = $(this).data('events').click;
if(foo.length <= 1) {
// $(this).next('.spacer').children().removeClass("visible");
}
$(this).unbind(e);
});
});未注释的行应该引用模糊的字段,但它似乎不起作用。有什么建议吗?
发布于 2010-10-29 23:16:27
您可以稍微延迟一下,如下所示:
$('.field').blur(function() {
var kids = $(this).next().children();
setTimeout(function() { kids.hide(); }, 10);
});这让你有时间在那些子链接消失之前点击。
发布于 2010-11-20 22:38:10
这就是我最终怎么做的:
var curFocus;
$(document).delegate('*','mousedown', function(){
if ((this != curFocus) && // don't bother if this was the previous active element
($(curFocus).is('.field')) && // if it was a .field that was blurred
!($(this).is('.adress'))
) {
$('.' + $(curFocus).attr("id")).removeClass("visible"); // take action based on the blurred element
}
curFocus = this; // log the newly focussed element for the next event
});发布于 2010-10-31 07:00:44
我相信你可以在这种情况下使用.not('a'):
$('.field').not('a').blur(function() {
$(this).next().children().hide();
});这没有经过测试,所以我不确定这是否会起作用。
https://stackoverflow.com/questions/4053123
复制相似问题