0
onclick関数を使って値を選択できますが、keyup/keydownを使って値を選択したいと思っています。 keyup/keydownを使用して正しい値に到達し、その値を選択する必要があるときに、どの機能を使用する必要がありますか。keyup/keydownの使い方とajaxのオートコンプリート機能の選択方法
$("#employer").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
url: "employerNameAutoSuggestionList?ajax=true",
data: { employer: request.term },
success: function (result) {
var arr =result.data;
$("#suggesstion-box").empty();
$("#suggesstion-box").show();
if($("#employer").val() == "")
{
$("#suggesstion-box").hide();
}
$("#suggesstion-box").append('<ul id ="empVal" style="list-style-type: none; display:inline" ></ul>');
var ul = document.getElementById("empVal");
for (var i = 0, length = arr.length; i < length; i++) {
var li = document.createElement("li");
li.appendChild(document.createTextNode(arr[i]));
ul.appendChild(li);
ul.onclick = function (li) {
$("#employer").css("background","#FFF");
$("#employer").val(li.target.innerText);
$("#suggesstion-box").hide();
}
}
arr = null;
},
error: function (xhr, status, error) {
alert(error.responseText);
}
});
}
});
$("#employer").on({
keyup: function() {
if ($(this).val() == "") {
$("#suggesstion-box").hide();
}
}
});
</script>
この上記のコードは正常に動作している私たちは、テキストボックスには何もありませんが、私はkeyUpイベント/ KeyDownイベントが動作するように新しい機能を追加したいと私は特定の値を選択することができるとき、それは提案箱の隠蔽のためであります。 –
私がチェックしたかったのは、 'keyup'イベントとそのコールバックメソッドを入れる構文です。 – sSD