[英]jquery autocomplete search input
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
...
<div id="search">
<form method="get" action="{% url 'main:home' %}">
<input type="text" name="q" placeholder="Поиск по сайту" value="{{ request.GET.q }}">
<input id="input_id" type="submit" value="Найти">
</form>
</div>
...
<script>
$('#search input[name="q"]').autocomplete({
'source': '{% url "main:home" %}',
'minLength': 2,
// 'appendTo': "#input:last"
});
</script>
自動完成刪除以前的輸入值 如果我按自動完成,以前的值就會消失。 我嘗試在注釋掉的版本中在行尾添加,但這不起作用。 需要替換最后一個未完成的單詞
$('#search input[name="q"]').autocomplete({
'source': '{% url "main:home" %}',
'minLength': 2,
'appendTo': "#search"
}).on( "autocompleteselect", function(event, ui) {
event.preventDefault();
var words = this.value.split(' ');
words[words.length - 1] = ui.item.value;
this.value = words.join(' ');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.