2010-03-16 20 views
0

我正在使用jquery自動完成,並且我的文本框中有一個關鍵事件。 當我輸入一個字母時,該函數被調用,但該框未被填充。Jquery自動完成不在關鍵點上觸發,除非焦點發生變化

一旦我點擊遠離盒子,然後再點擊回到它,自動完成功能很好。

真的很奇怪的問題,我不知道如何解決它。任何幫助,將不勝感激。

這裏是我的代碼

$(document).ready(function(){ 

    var x; 
    var output; 
    x = document.getElementById('site').value; 

    $.getJSON(url,{field: "name",value: x, comparison: "LIKE"}, 
    function(json){  
     //code to format output 
     $("#site").autocomplete(output, json); 
    }); 
}); 



<input type ="text" size ="40" id="site"></input> 

回答

0

什麼迷我是該插件的文件說

autocomplete(url or data, options) 

應該不是你的電話這個樣子的?這個輸出變量是什麼?

$("#site").autocomplete(json, options) 

哪個自動完成?小心提供一個網址。無論如何,你嘗試手動觸發焦點?

... 
function(json){ 
    //code to format output 
    $("#site").autocomplete(output, json).trigger("focus"); 
}); 
... 
+0

http://docs.jquery.com/Plugins/Autocomplete 我試過聚焦觸發信號,並沒有工作 – TheIG

+0

檢查擴展答案 – jitter

+0

在我的情況下,JSON是數據。而輸出變量「#site」是結果出現的div的id – TheIG

相關問題