在较小的选项列表中,自动完成下拉列表确实显示焦点。但如果选项超过特定数字(确切地说是50),则不再显示。
无论列表中的选项数量是多少,如何显示?
$(document).ready(function() {
var sst;
//auto complete for artist
$('#artist').autocomplete({
source: 'artists.php',
minLength: 0,
select: function(a, b) {
sst = b.item.value;
}
}).focus(function() {
$(this).data("uiAutocomplete").search($(this).val());
});
//auto complete for title
$('#title').autocomplete({
source: function(request, response) {
$.ajax({
url: "titles.php",
dataType: "json",
data: {
q1: sst,
q2: request.term
},
success: function(data) {
response(data);
}
});
},
minLength: 0
}).on('focus', function(event) {
$(this).autocomplete("search", "");
});
});
mysql查询:
<?php
$db = mysql_connect('localhost','root','1313');
if(!$db){
die( "connection failed ");
}
$db_s = mysql_select_db("LYRICSFINDER",$db);
$data = array();
$searchTerm1 = trim(strip_tags($_GET["q1"]));
$searchTerm1 = addslashes($searchTerm1);
$searchTerm2 = trim(strip_tags($_GET["q2"]));
$searchTerm2 = addslashes($searchTerm2);
$query = "SELECT TITLE FROM DATA WHERE ARTIST LIKE '%".$searchTerm1."%' AND TITLE LIKE '%".$searchTerm2."%' ORDER BY TITLE ASC";
$result = mysql_query($query,$db);
$i=0;
while($row = mysql_fetch_assoc($result) ){
$data[] = $row['TITLE'];
$i++;
if($i>50)break;
}
mysql_close($db);
echo json_encode($data);
?>