0

我正在尝试使用 ajax 和 jquery 实时验证数据,我的 ajax 函数每 2 秒返回一次数据,所以我想为 focusout 添加一些时间。

$("#username").focusout(function() {
  setTimeout(function() {
    if (/^[a-zA-Z][a-zA-Z0-9-_\.]{1,20}$/.test($(this).val()) && $(this).val().trim() !== "" && $(this).attr('availability') === 'true') {
      $(this).css("border-color", "#37ff00");
    } else {
      $(this).css("border-color", "red");
    }
  }, 1000);
});
4

1 回答 1

0

我替换$(this)$("#username"),它现在可以工作了。

于 2015-01-30T18:20:59.783 回答