그래서이 자동 완성 기능은 자바 스크립트로 제공되지만 완전히 작동하지는 않습니다. 자동 완성 목록을 클릭 할 수 없으므로 목록에서 항목을 클릭해도 텍스트 상자에 아무 것도 채워지지 않습니다.자동 완성 기능이 작동하지 않습니다.
HTML :
<input type="text" name="naam_klant" size="20" id="naam_klant" onkeyup="lookup(this.value);" onblur="fill();" >
<div class="suggestionsBox" id="suggestions" style="display: none;">
<div class="suggestionList" id="autoSuggestionsList">
</div>
</div>
자바 스크립트 :
function lookup(inputString)
{
if(inputString.length == 0)
{
$('#suggestions').hide();
}
else
{
$.post("sql_naam_klant.php", {queryString: ""+inputString+""}, function(data)
{
if(data.length >0)
{
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
}
function fill(thisValue)
{
$('.inputString').val(thisValue);
setTimeout("$('.suggestions').hide();", 200);
}
검색어 :
if(isset($_POST['queryString']))
{
$queryString = $db->real_escape_string($_POST['queryString']);
// Is the string length greater than 0?
if(strlen($queryString) >0)
{
$query = $db->query("SELECT naam_klant FROM overboekingen WHERE naam_klant LIKE '$queryString%' LIMIT 10");
if($query)
{
while ($result = $query ->fetch_object())
{
echo '<li onClick="fill(\''.$result->naam_klant.'\');">'.$result->naam_klant.'</li>';
}
}
else
{
echo 'ERROR: There was a problem with the query.';
}
}
else
{
} // There is a queryString.
}
else
{
echo 'There should be no direct access to this naam_klant script!';
}
}
jQuery를 자동 완성 기능을 사용하는 것이 훨씬 낫다. 여기에 그것은 http://jqueryui.com/autocomplete/#remote-jsonp –
입니다. mysql에서 자동 완성해야합니다. 텍스트 상자에 부분적으로 채우기를 제외하고는 훌륭하게 작동합니다. – user3455717