【问题标题】:Select data using arrow keys,from ajax suggestion text box使用箭头键从 ajax 建议文本框中选择数据
【发布时间】:2011-11-09 07:20:54
【问题描述】:

我有一个输入文本框,用户在其中输入一些数据并按下回车键。然后显示一些建议,然后用户应该能够使用箭头键从这些建议中选择值。然后他使用回车键从建议中选择一个数据,这个选定的值应该显示在输入文本字段中。 我可以使用鼠标执行所有这些操作,但现在我想使用箭头键执行此操作。这就是我使用 jquery 实现输入键事件的方式。

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

我正在寻找类似的东西。

【问题讨论】:

  • 这取决于 'menusearch' 函数生成的 html。您可以将此添加到问题中吗?
  • @Layoric 抱歉无法理解您的问题
  • 在您的问题中不清楚“菜单搜索”功能在做什么,这使得提供建议或帮助变得困难。如果您能提供“menusearch”的代码,我或许可以提供一些建议。

标签: php javascript jquery


【解决方案1】:

我现在有你需要的类似任务:

$("#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 
}});

抱歉,我没有看到您的 html 用于自动完成框,所以我可以通过您提供的信息告诉您这些信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 1970-01-01
    • 2018-01-04
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    相关资源
    最近更新 更多