为什么这会失败...

$( 'div.contactAperson input' ).not( 'input.hadFocus' ).focus(function() {
    $(this).attr('value', '' );
});

...这意味着要嗅出尚未获得类.hadFocus的输入,然后当该子集中的一个子集获得焦点时,应将值转换为null。

现在,输入值总是会跳动-测试.not('input.hadFocus')无法停止执行。

顺便说一句,上面的代码之前是下面的代码,可以正常工作:
$( 'div.contactAperson input' ).focus(function() {
    $( this ).addClass( 'hadFocus' );
});

谢谢您的聪明-欢呼声-艾伦

最佳答案

您需要处理程序根据元素的当前状态运行-
而不是绑定(bind)时的状态。您可能需要使用live绑定(bind)。

尝试这样的事情:

$('div.contactAperson input:not(.hadFocus)').live('focus', function() {
    $(this).attr('value', '' );
});

关于jquery-selectors - jQuery : How to find elements *without* a certain class,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2715330/

10-11 09:21
查看更多