0
我在輸入字段中使用jquery ui自動完成。我使用select事件觸發了一些操作,但是如果用戶使用enter鍵選擇了某些東西,這也會觸發keyup事件。觸發不同的事件自動完成選擇和鍵入輸入
什麼我想要做的:
$('.my-input').autocomplete({
source: availableTags,
select: function(event, ui) {
console.log('here goes an action triggered by the selection of an autocomplete suggestion');
}
});
$('.my-input').keyup(function(e) {
if (e.keyCode == 13) {
console.log('here goes an action triggered by the enter key');
}
});
使用此代碼,動作應該是按ENTER鍵,當我使用輸入選擇自動完成建議被觸發觸發。我怎麼能避免它?
感謝您的回答,但實際上我需要相反:檢查keyup事件中,如果它是一個簡單的回車按下輸入或者點擊輸入壓選擇一些東西。 – fksr86