2011-11-10 76 views
3

很簡單的問題(但我不能在網上找到了答案...):我有一個自動完成字段中設定這樣:jQuery用戶界面自動完成如何加載默認值列表

$(document).ready -> 
     $('#projecttask_user_name').autocomplete 
       source: "/autocomplete/users" 

我希望jquery在選擇字段時觸發源,以便獲得完整的可能列表,即使我沒有在字段中輸入任何內容。

我該怎麼做?謝謝!

回答

6

您可以將minLength選項設置爲0,並調用search方法當輸入元素獲得焦點:

$("#projecttask_user_name").autocomplete({ 
    source: "/autocomplete/users", 
    minLength: 0 
}).focus(function() { 
    $(this).autocomplete("search", this.value); 
}); 
+0

好極了!非常感謝! – ndemoreau

相關問題