[英]jquery tree traversal issue
$('.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);
});
});
每当我模糊分类为.field的字段时,我都会尝试删除“可见的类”,除非单击带有.adress类的元素。
字段模糊和地址单击可以正常工作(我对警报感到厌倦),但不能删除班级,有人知道为什么吗?
如果删除了not(“。adress”)函数,则删除类将起作用! 像这样:
$('.field').blur(function() {
(this).next('.spacer').children().removeClass("visible");
});
您在//$(this
之后有一个额外的引号。您无需引用this
变量。
此外,您的*选择器可以简化为$(':not(.address)')
您能提供一个HTML示例吗?
每当我模糊分类为.field的字段时,我都会尝试删除“可见的类”,除非单击带有.adress类的元素。
这很棘手。 您当前的代码正在执行的操作是,每次使用class field
模糊元素时,都将绑定click
事件处理程序。 这将无法正常工作。
我想到的最好的跨浏览器方式是侦听focus
事件并记录哪个元素已获得焦点,并根据需要对先前处于活动状态的元素采取措施:
$(document).ready(function(){
var curFocus;
$(document.body).delegate('*','focus', 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')) // the newly focused field is an .adress
) {
$(curFocus).next('.spacer').children().removeClass("visible"); // take action based on the blurred element
}
curFocus = this; // log the newly focussed element for the next event
});
});
这可能性能很差。 如果您不担心跨浏览器的兼容性,尤其是对于旧版本,则document.activeElement
可能会让您感兴趣。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.