开发者

jQuery autocomplete; want Return key to behave as Tab

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜