jQuery最近()不适合我(或者我不是为它工作)
鉴于此jQuery:
$('div.MvcFieldWrapper :input').focus(function() { $(this).closest('label.MvcDynamicFieldError').fadeOut(); });
并给出这个HTML:
当我专注于输入时,为什么标签不会淡出? 我确信焦点事件正在发生。
谢谢
最近看起来通过“父母”而不是兄弟姐妹。 你想要的是prevAll
:
$('div.MvcFieldWrapper :input').focus(function() { $(this).prevAll('label.MvcDynamicFieldError').fadeOut(); });
closest
实际上意味着“找到与选择器匹配的最近祖先,包括已满足要求的已选元素。”