douchunji1885 2014-09-30 15:02
浏览 46

jquery autocomplete显示div内的返回html结果

Here I'm trying to do autocomplete search box. When I type the text in textbox it filter the results correctly. I have checked in my console. I have seen the results in HTML tab window. But, I can't able to get the results under the textbox. You can see the div after input field . I want to display the results in this div.

I have tried this line $('#result').html(data); but I didn't get the result inside the div. How do I show the html results inside the div?

index.php

<script type="text/javascript">
$(function() {
$( "#searchid" ).autocomplete(
    {
            source: "<?=asort_get_url(SEARCH_BOX)?>",
            minLength: 1,
            select: function (event,ui) {
            //alert(ui.item.url);
            $('#result').empty();
            window.location = ui.item.url;          
    }
    }).data( "ui-autocomplete" )._renderItem = function( ul, item ){
         $('#result').html(data);
    };
});
</script>

<input type="text" class="search" id="searchid" />
<div id="result"></div>

search_box.php

$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $query = parse_url($url, PHP_URL_QUERY);
    parse_str($query);
    parse_str($query, $arr);
$q = mysql_real_escape_string(trim($term, '/'));
        $sql = "SELECT model_name, maker_url, model_url FROM ".TBL_CAR_ADD_MODELS." WHERE model_status = '1' AND model_url != '".$model_url."' AND model_name LIKE '%$q%' LIMIT 7";
        $res = mysql_query($sql, $CN);
        while($row = mysql_fetch_array($res))
        {
           echo "<a onMouseOver=\"this.style.backgroundColor='#09F'\" onMouseOut=\"this.style.backgroundColor='#F2F2F2'\" href=".asort_get_url(CAR_MAKE, $row['maker_url'], $row['model_url'])." style='width: 380px; height: 95px; text-decoration: none; display: inline-block; margin: 0 auto; color: #000; margin-left: -20px; background :#F2F2F2; border-bottom: 1px solid #CCC;'><img style='margin:5px;' alt='".$row['model_name']."' src=".fa_model_image_path("thumb", $row['maker_url'],$row['model_url'])." />"."<span style=' margin-left: 20px; margin-top: 0px; position: absolute; display: inline-block;'>".$row['model_name']."</span>"."</a>";
        }
  • 写回答

1条回答 默认 最新

  • droxlzcgnr639823 2014-09-30 17:22
    关注

    you have to code something like this

    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
      $('#result' ).html(item.value)
                 };
    
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题