2009-05-01 23 views
0

我有一個非常有趣的案例,其中JQuery自動完成字段沒有響應我第一次鍵入文本框,但是當我TAB外部的文本框,然後返回到第二次它的文本框開始迴應和結果顯示爲我開始鍵入。爲什麼JQuery Autocomplete未執行?

當我使用螢火蟲,我實際上可以看到我的應用程序中的AJAX函數被調用,並且結果被返回到html模板,但結果未被顯示,可能是什麼原因導致了這種行爲?

我的功能綁定代碼:

$(function() 
    { 
    $(document).ready(function(){ 
     $("#tags1").bind("keyup",autoFill) 
     }); 
    }); 

我的自動完成功能

function autoFill(){ 
      $("#tags1").autocomplete("/taglookup/", { 
     width: 320, 
     max: 4, 
     highlight: false, 
     multiple: true, 
     multipleSeparator:",", 
     scroll: true, 
     scrollHeight: 300, 
     delay: 10 
     }); 
     } 

我的文本框字段:

<input type="text" style="width: 400px" id="tags1" name="tags1" value=""> 

回答

3

你爲什麼做對KEYUP自動完成()調用?我認爲這可能會導致你的問題。我會嘗試直接從文檔就緒事件調用autocomplete()。

$(document).ready(function(){ 

     $("#tags1").autocomplete("/taglookup/", { 
     width: 320, 
     max: 4, 
     highlight: false, 
     multiple: true, 
     multipleSeparator:",", 
     scroll: true, 
     scrollHeight: 300, 
     delay: 10 
     }); 

     }); 
0

如果您使用的是我今天所使用的相同的自動完成(上另一臺電腦抱歉 - 找不到確切的版本) - 那麼你不需要在keyu上綁定p - 只在啓動時綁定一次 -

<script> 
    $('#tags1').autocomplete(....); 
</script> 

自動完成功能,處理所有的按鍵/聚焦變化等