简体   繁体   English

从Ajax建议文本框中使用箭头键选择数据

[英]Select data using arrow keys,from ajax suggestion text box

I am having a input text box, in which user enters some data and presses enter key. 我有一个输入文本框,用户在其中输入一些数据并按Enter键。 Then some suggestion are shown ,then the user should be able to select values from these suggestions using arrow keys. 然后显示一些建议,然后用户应该能够使用箭头键从这些建议中选择值。 Then he selects a data from suggestions using enter key and this selected value should be shown in the input text field. 然后,他使用回车键从建议中选择一个数据,并且所选的值应显示在输入文本字段中。 I am able perform all this using mouse, but now i want to do this using arrow keys. 我可以使用鼠标执行所有这些操作,但是现在我想使用箭头键执行此操作。 This is how i implemented enter key event using jquery. 这就是我使用jquery实现enter key event的方式。

 $('#dishes').keydown(function (e){
    if(e.keyCode == 13){
       menusearch('dishes','<?=$user_id?>') ;
    }
}) 

I am looking something along these lines. 我正在按照这些思路寻找东西。

I had similar task as you need now: 我现在有与您需要类似的任务:

$("#searchterm2").keyup(function(event) {
if ( event.keyCode != '13' && event.keyCode != '38' && event.keyCode != '40') { //user input some symbol
    if( helpbox_closed == 1 ){ //if autocomplete is still hidden
        $('div.saveSearchTmp > input:last').val($("#searchterm2").val()); // saving user's value
        $("#helpBox").show() //show autocomplete box
                     .load("searchAjax.php", {words: $("#searchterm2").val()},function(){
            checkAJAX(); //creating ajax request to get fields by user's value and setting helpbox_closed = 0
        });
    }
}

if( ( event.keyCode == '40' || event.keyCode == '38') && $("#helpBox").css('display') == 'none' )
    $("#searchterm2").keyup(); //if user push up or down and autocomplete box is hidden we show it
else if( event.keyCode == '40'){
    helpbox_closed = 0;
    //your code here to move current li/div/or what you have 
}else if( event.keyCode == '38'){
    helpbox_closed = 0;
    //your code here to move current li/div/or what you have 
}});

Sorry I don't see your html for autocomplete box so this is all what I can tell you with information you provide. 抱歉,我没有看到用于自动填充的html框,所以这就是我所提供信息的全部内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM