开发者

Why will focusout(); in jQuery not perform a function after focusing out of a field?

I am trying to use the focusout(http://api.jquery.com/focusout/) function in jQuery, to perform a function after the user focus away from an input form field, but it's not working.

Here is my code:

$("#employee_id").focusout(function(){
  var employeeId = $("#employee_id").val();
  if(employeeId == '') {
    $("#employee_id").after('<div class="error">Your employee id number is required.</div>');
    hasError = true;
  }
});

I am using jquery-1.3.2.min.js since another plugin I am using(qtip) is giving me an error when I try to use jquery-1.4.2.min.js.

How can 开发者_StackOverflow社区I make the focusout event work, or is there another way to do what I am trying to accomplish?


Since you just seem to care about that field and not the parent/bubbling, use .blur():

$("#employee_id").blur(function(){
  if($(this).val() == '') {
    $(this).after('<div class="error">Your employee id number is required.</div>');
    hasError = true;
  }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜