簡體   English   中英

下拉輸入字段

[英]Drop down input field

我的搜索表單中有一個下拉字段,但問題是我收到一條消息:(17個結果可用,使用向上和向下箭頭鍵導航。)在輸入字段下而不是結果。

我的代碼是:

 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" ></script> 
        <script type="text/javascript">
$(document).ready(function() {
    $(function(){
        $( "#destination" ).autocomplete({
            source: function(request, response) {
                $.ajax({
                url: "http://localhost/fantastic/Travels/search_fields",
                data: { term: $("#destination").val()},
                dataType: "json",
                type: "POST",
               success: function(data){
   var resp = $.map(data,function(obj){
        return obj.destination;
   }); 
   response(resp);
}
            });
        },
        minLength: 1
        });
    });
});
</script>

我的控制器代碼是:

    function search_fields(){
    $term = $this->input->post('term', TRUE);   

     $search_data = $this->Travel->search_field($term); 
     echo json_encode($search_data);

}

我的模型代碼是:

 function search_field($term){

    $query = $this->db->query("SELECT distinct(destination) FROM travels_detail WHERE destination LIKE '".$term."%' group by destination");
    return $query->result_array();
}

我將相同的代碼應用到另一個站點,它正在運行。 但在另一個網站上,它給我的消息“17個結果可用,使用向上和向下箭頭鍵進行導航。” 這17個結果顯示在keyup和keydown按鈕上。

任何人都有一些想法? 請告訴我

SELECT distinct(destination) FROM travels_detail WHERE destination LIKE '".$term."%' group by destination

您需要按目的地刪除組,這是多余的。

你可以嘗試一下,讓我知道它的樣子嗎?

這是一個css庫的問題。

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />

放置該庫后問題得到解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM