如何将标题属性添加到自动填充,并在鼠标滑过选项时显示标题。
<input type="text" id="txtitem" name="txtitem" class="form-control items" onKeydown="$(this).autocomplete({source: 'demo1.php',minLength:0 });" />
demo1.php:
<?php
//database configuration
$dbHost = 'localhost';
$dbUsername = 'root';
$dbPassword = '';
$dbName = 'sample';
//connect with the database
$db = new mysqli($dbHost,$dbUsername,$dbPassword,$dbName);
//get search term
$searchTerm = $_GET['term'];
//get matched data from skills table
$query = $db->query("SELECT * FROM item_list WHERE product_name LIKE '%".$searchTerm."%' GROUP BY product_name ORDER BY product_name ASC");
while ($row = $query->fetch_assoc()) {
$data[] = $row['product_name'];
}
//return json data
echo json_encode($data);
?>
答案 0 :(得分:0)
在自动填充后添加:
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" ).data("item.autocomplete", item)
.append( "<a title=" + item.product_name + ">" + item.product_name + "</a>")
.appendTo( ul );
}