【问题标题】:Drop down input field下拉输入框
【发布时间】:2016-12-22 00:24:42
【问题描述】:

我的搜索表单中有一个下拉字段,但问题是我收到一条消息:(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 按钮上。

有人知道吗??请告诉我

【问题讨论】:

标签: php jquery ajax codeigniter


【解决方案1】:
SELECT distinct(destination) FROM travels_detail WHERE destination LIKE '".$term."%' group by destination

您需要按目的地删除组,这是多余的。

你能试试看,然后告诉我它的样子吗?

【讨论】:

  • 您正在返回一个数组,即所有为真的值。您需要将它们作为数组中的单独值读入,否则它们将被视为唯一的答案。
  • for($i=0; $ioption[0]; }
  • 它在一个单独的页面上工作,但是当我用我的模板配置它时它没有显示结果
  • 你的意思是你的css模板?这应该与此无关。
  • 这是 css 的问题,缺少 css 库。感谢您尝试帮助我。
【解决方案2】:

这是 css 库的问题。

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

放置该库后,问题就解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 2016-04-04
    • 1970-01-01
    • 2011-08-03
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    相关资源
    最近更新 更多