为什么这会失败......
$( 'div.contactAperson input' ).not( 'input.hadFocus' ).focus(function() {
$(this).attr('value', '' );
});
...它意味着嗅出不得到类.hadFocus的输入,然后当其中一个子集获得焦点时,它应该将值变为null。
现在,输入值总是被破坏 - 测试.not('input.hadFocus')无法停止执行。
顺便说一句,在上面的代码之前是以下代码,它正常工作:
$( 'div.contactAperson input' ).focus(function() {
$( this ).addClass( 'hadFocus' );
});
感谢任何聪明 - 欢呼,-Alan
答案 0 :(得分:5)
您需要根据元素的当前状态运行处理程序 - 不是受约束的国家。您可能需要使用live绑定。
尝试这样的事情:
$('div.contactAperson input:not(.hadFocus)').live('focus', function() {
$(this).attr('value', '' );
});
答案 1 :(得分:4)
$( 'div.contactAperson > :input' ).not( ':input.hadFocus' ).focus(function() {
$(this).attr('value', '' );
});
祝你好运