2011-07-31 23 views
3

下面的代碼的行爲不同,當標籤進入鍵按下:jQuery自動完成;要返回鍵表現爲標籤

- 標籤與所選項目的值替換文本字段的值,並重點去到下一個輸入框

- 進入與所選項目的價值,但重點替換文本字段的值不進入下一個輸入框

如何更改的行爲輸入以便將焦點轉到下一個輸入框?

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

我嘗試添加以下行:

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

這是行不通的。見http://jsfiddle.net/YbPVX/4/

回答

5

試試這個

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

- 的jQuery和jQuery UI的更高版本>http://jsfiddle.net/YbPVX/5/

+0

這隻適用。謝謝! – Randomblue