javascript - keypress event in autocomplete jquery ui - Stack Overflow

I want to show the value of the autoplete suggesion on textbox only when the user is selecting the sugg

I want to show the value of the autoplete suggesion on textbox only when the user is selecting the suggession. I tried

$("#trainerNameAutoComplete").autoplete({
    source:"serverpage.php?id="+1,
    minLength:1,
    focus: function( event, ui ){
        $("#trainerNameAutoComplete").val('');
    },
    keypress: function(event,ui){
        if ((event.which == 38||event.Keycode ==38) || (event.which == 40||event.Keycode ==40)) {
            console.log("key down");
            $("#trainerNameAutoComplete").val('');
        }
    },
    select:function(event,ui){
        somefunction();
    }
});

but the value is cleared in textbox when I hover the mouse over the suggestion but not when I press up and down arrow keys.

I want to show the value of the autoplete suggesion on textbox only when the user is selecting the suggession. I tried

$("#trainerNameAutoComplete").autoplete({
    source:"serverpage.php?id="+1,
    minLength:1,
    focus: function( event, ui ){
        $("#trainerNameAutoComplete").val('');
    },
    keypress: function(event,ui){
        if ((event.which == 38||event.Keycode ==38) || (event.which == 40||event.Keycode ==40)) {
            console.log("key down");
            $("#trainerNameAutoComplete").val('');
        }
    },
    select:function(event,ui){
        somefunction();
    }
});

but the value is cleared in textbox when I hover the mouse over the suggestion but not when I press up and down arrow keys.

Share Improve this question edited Aug 31, 2016 at 17:02 Mark Schultheiss 34.2k12 gold badges72 silver badges113 bronze badges asked Feb 28, 2013 at 14:18 AshwinAshwin 4553 gold badges7 silver badges15 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 1
 keydown: function(event,ui){
        event.preventDefault();
        if (event.Keycode ==38||event.Keycode ==40) {
            console.log("key down");
            $("#trainerNameAutoComplete").val('');
        }
    },

try this..instead of your keypress event

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745277967a4620145.html

相关推荐

  • javascript - keypress event in autocomplete jquery ui - Stack Overflow

    I want to show the value of the autoplete suggesion on textbox only when the user is selecting the sugg

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信