2014-09-30 71 views
0

在這裏,我試圖做自動完成搜索框裏面的返回HTML結果。當我在文本框中鍵入文本它正確地過濾結果。我檢查了我的控制檯。我在HTML選項卡窗口中看到了結果。但是,我不能抽到文本框下的結果。您可以在輸入字段後看到div。我想在這個div中顯示結果。jquery的自動完成功能顯示在div

我已經試過這條線$('#result').html(data);但我沒有得到DIV中的結果。如何顯示在div裏面的HTML結果?

$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

你必須編寫這樣的事情

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

的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