0

我使用jquery.autocomplete.js用於自動完成文本框。
如何修復jQuery中的文本框自動完成?

我得到按鍵事件的所有位置記錄。
按鍵事件我傳遞了位置文本框的文本值。

for eq。我寫文本「Lo」,那麼每次從SQL數據庫獲得新建議時,它都會獲得以「Lo」開頭的所有記錄。

我的問題是。我在文本框下看到了兩個,三個或更多的列表框作爲建議.. 我寫了.unautocomplete()方法來刪除每個按鍵事件中的以前的建議列表。 如何解決從文本框以前unautocomplte名單..

在我的自動完成我看到自動完成建議列表中顯示一個以上的建議列表.. 如何解決這個問題..
下面我寫我的代碼。

<script> 
$('#<%= txtLocation.ClientID %>').onkeypress(function() { 
    if ($('#<%= txtLocation.ClientID %>').val().length >= 1) { 
    GetCitiesLikeList($('#<%= txtLocation.ClientID %>').val()); 
    } 
}); 

function GetCitiesLikeList(objcity) { 
    if (objcity != null && objcity != "") {   
     $.ajax({ 
      type: "POST", 
      url: "http://www.myweburl.com/webservices.asmx/GetCitiesLikeList", 
      data: "{ City : '" + objcity + "'}", 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: function(msg) { 
       if (msg.d != null && msg.d != "") {    
        cities = msg.d.split(",");      
        $(".location").autocomplete(cities, { 
         matchContains: true, 
         minChars: 0 
        }); 
       } 
       else 
       $(".location").unautocomplete(); 
      }, 
      error: function(xhr, ajaxOptions, thrownError) {return false;} 
     }); 
    } 
    else 
     $(".location").unautocomplete(); 
} 
</script> 


看看這個圖片是什麼問題,我autocompleter建議名單是怎麼回事。
enter image description here

給我這個解決方案。
-Thanks
ABHI

回答

1

你並不需要使用獨立的自動完成插件,因爲它現在是jQueryUI的的part

+0

我使用http://docs.jquery.com/Plugins/autocomplete插件。 – 2011-04-13 10:43:44

1

我不知道如果我讓你正確地說的話100%,但只是幾件事情:

  1. 你並不需要手動等待keypress事件jQuery用戶界面自動完成。當你在一個元素上調用.autocomplete()時,它已經爲你做了。
  2. 自動完成功能還可以使用您在此處執行的AJAX處理項目羣體。

所以我猜你爲什麼會得到兩倍的名單是因爲你在技術上做了什麼自動完成再次爲你做(手動)。

+0

我在按鍵事件中獲取記錄,因此它獲取不止一次。所以我得到多個

到HTML源..所以我解決了這個問題。 – 2011-04-13 10:40:33