I have just finished adding a search bar into my page. It pretty much all works fine, however, I would like the autosuggestions to disappear after clicking outside of the field. How would I do this? I am using HTML5 and my codes are:
$(document) .ready(function() {
$('.autosuggest').keyup(function() {
var search_term = $(this).val();
$.post('search.php', {search_term:search_term}, function(data) {
$(".result").html(data);
$('.result li').click(function() {
var result_value = $(this).text();
$('.autosuggest').val(result_value);
$('.result').html('');
});
});
});
});
Not too sure my php is needed but just in case...
', $row['town'], '';
}
}
?>
以上就是Remove autosuggest text when clicking off field的详细内容,更多请关注web前端其它相关文章!