最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery autocomplete; want Return key to behave as Tab - Stack Overflow

programmeradmin1浏览0评论

The following code behaves different when tab and enter keys are pressed:

--tab replaces the text field's value with the value of the selected item and focus goes to the next input box

--enter replaces the text field's value with the value of the selected item but the focus does not go to the next input box

How do I change the behavior of enter so that the focus goes to the next input box?

$('input').autoplete({
    autoFocus: true,
    source: ["test","some text"],
    delay: 0
});

I have tried to add the following line:

select: function(event, ui) { if (event.keyCode == 13) { trigger({ type : 'keypress', which : 9 }); } }

This doesn't work. See /

The following code behaves different when tab and enter keys are pressed:

--tab replaces the text field's value with the value of the selected item and focus goes to the next input box

--enter replaces the text field's value with the value of the selected item but the focus does not go to the next input box

How do I change the behavior of enter so that the focus goes to the next input box?

$('input').autoplete({
    autoFocus: true,
    source: ["test","some text"],
    delay: 0
});

I have tried to add the following line:

select: function(event, ui) { if (event.keyCode == 13) { trigger({ type : 'keypress', which : 9 }); } }

This doesn't work. See http://jsfiddle/YbPVX/4/

Share Improve this question asked Jul 31, 2011 at 22:31 RandomblueRandomblue 116k150 gold badges363 silver badges558 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Try this

$('input').autoplete({
    autoFocus: true,
    source: ["test","some text"],
    delay: 0,
    select: function(event, ui) { if (event.keyCode == 13) { 
       $(this).next("input").focus().select();
    } }
});

-> http://jsfiddle/YbPVX/5/

发布评论

评论列表(0)

  1. 暂无评论