开发者

jQuery autocomplete; want Return key to behave as Tab

开发者 https://www.devze.com 2023-03-23 23:20 出处:网络
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

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 select开发者_开发百科ed 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').autocomplete({
    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.net/YbPVX/4/


Try this

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消