私のコードでは、keyup
イベントを入力にバインドして、入力値の長さが3であるかどうかを確認します。そうである場合は、サーバーにAjax呼び出しを行い、データベースからこれらの3文字で始まるレコードを取得してからjQueryを開始します。ソースとのオートコンプリート-データベースからのデータ。
問題は、ユーザーが3文字を入力すると、オートコンプリートのソースが取得され、4番目の文字を入力したときにのみオートコンプリートが開始されることです。その動作を変更して、3文字を入力し、ソースにオートコンプリートを開始させることは可能ですか?
これが私のコードです:
var keypresshandler = function () {
var strin = document.getElementById('txtInput').value;
newstr = strin.replace(/[^\u0400-\u04FF0-9]/gi, '');
if (newstr.length<3)
{
$( "#txtInput" ).autocomplete( "destroy" );
} else
if (newstr.length==3)
{
triming();
}
}
$(function() {
$('#txtInput').bind('keyup', keypresshandler);
});
function triming() {
//make asynchronous ajax call to server to get the source of my autocomplete
// alert (mec.length);
$( "#txtInput" ).autocomplete({source: mec});
}
}