2013-03-18 30 views
3

我使用下面的代碼爲Ajax建議如何限制用戶選擇的形式AJAX自動compleate建議

<script type="text/javascript"> 
$(function(){ 
    setAutoComplete("searchField", "results", "<?php echo base_url(); ?>index.php/user/autofillvalue/<?php echo $this->uri->segment(3); ?>?part="); 
}); 

和HTML我的代碼是

<div class="input text required" id="auto"> 
     <input id="searchField" type="text" name="searchField" class='inp-form' autocomplete="off"> 
</div> 

的推薦代碼json編碼。我想限制最終用戶只選擇表單建議值。怎麼可能?

回答

3

如您所知,JQuery documentation page詳細說明了一個選項,稱爲mustMatch。但如this post所解釋的那樣,它不可用。但是,救援來了this post。對於如何解決問題有幾點建議。下面是從頁的一個解決方案,通過@Anonymous和@Elliot寫着:

補充一點:

change: function (event, ui) { 
    if (!ui.item) { 
     $(this).val(''); 
    } 
} 

這:

autoFocus: true 
相關問題