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/
精彩评论