2
我有一個JQuery UI自動完成字段,可以在後臺訪問Ruby功能。輸入框不會觸發到服務器的加載選項的呼叫。然而,按下向下鍵可以做到這一點,並在此後正常工作。任何想法,爲什麼這可能是?JQuery UI自動完成不會觸發打字
HTML
<div id="subject_select_dialog" class="ui-dialog-content ui-widget-content" style="width: auto; min-height: 0px; height: 141px; " scrolltop="0" scrollleft="0">
<input id="subject_select" name="subject" size="70" type="text" class="ui-autocomplete-input" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">
<button id="subject_select_clear" name="button" type="clear">Clear</button>
...
</div>
的JavaScript
$("#subject_select").autocomplete({
source: "https://stackoverflow.com/users/autocomplete",
minLength: 2,
focus: function(event, ui) {
$("#subject_select").val(ui.item.label);
return false;
},
select: function(event, ui) {
$("#subject_select").val(ui.item.label)
$("#subject_select_results").html(ui.item.label)
$("#subject_select_id").val(ui.item.value)
return false;
}
});
紅寶石
def autocomplete
render :json => UserProfile.list_by_name(params[:term]).to_json
end
編輯:
檢查生成的HTML,它是我的標記字段作爲Autocomplete="off"
。當我在調試器中手動更改該值時,會出現正確的行爲。爲什麼會用這樣的屬性標記它,我該如何解決它?
Firebug /其他調試工具是否顯示爲鍵入而觸發的任何請求?該字段上是否有其他'keypress/keyup/keydown'處理程序可能會阻止此自動完成工作? – GregL 2012-02-27 23:19:27
作爲一個完整性檢查,您至少要輸入2個字符? – jmoerdyk 2012-02-27 23:25:58
請修復您的HTML,以便它是您的後端腳本實際生成的內容。 – Madbreaks 2012-02-27 23:26:16