私は ajax と jquery でライブ データを検証しようとしています。私の ajax 関数は 2 秒ごとにデータを返すので、フォーカスアウトにタイムアウトを追加したいと思います。
$("#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);
});