开发者

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

开发者 https://www.devze.com 2022-12-21 16:00 出处:网络
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.

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

精彩评论

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