我在Django项目中使用jQueryUi建立了自动完成表单。
自动完成工作正常。问题是,建议没有显示在我的表格下,而是显示在屏幕的右侧。
我需要将建议显示在我的搜索字段正下方,并仅显示与我的搜索相匹配的前10个产品。
我的HTML:
<div class="ui-widget">
<input id="prod" class="form-control mr-sm-2" type="text" name="query" placeholder="">
</div>
我的AJAX:
$(function() {
$("#prod").autocomplete({
source: "/finder/search_auto",
select: function (event, ui) {
AutoCompleteSelectHandler(event, ui)
},
minLength: 2,
});
});
function AutoCompleteSelectHandler(event, ui)
{
var selectedObj = ui.item;
}
我的views.py:
$(function() {
$("#prod").autocomplete({
source: "/finder/search_auto",
select: function (event, ui) {
AutoCompleteSelectHandler(event, ui)
},
minLength: 2,
});
});$( "#prod" ).autocomplete({
position: { my : "right top", at: "right bottom" }
});
function AutoCompleteSelectHandler(event, ui)
{
var selectedObj = ui.item;
}
用最新版本更新:
<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/jqueryui/1.12.1/jquery-ui.min.js"></script>
这应该够了吧。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句