捕获所有文本框的焦点事件 - JQuery

时间:2014-04-08 14:48:20

标签: jquery

我在表单中有很多文本框。当其各自的值未通过验证时,类别“有错误”。已应用,它会在文本框中添加红色边框。

如果该文本框获得焦点,我想撤消此类。

这样的东西
$(document).on('focus',find(':input'),function(){
    $(this).removeClass('has-error');
});

这是怎么做到的?

2 个答案:

答案 0 :(得分:3)

您只需使用find(':input')

即可':input.has-error'
$(document).on('focus', ':input.has-error' ,function(){
   $(this).removeClass('has-error');
});

并确保您的代码位于DOM Ready

答案 1 :(得分:1)

只是做:

$(document).on("focus", "input:text.has-error", function() {
相关问题