[英]Autocomplete triggered on page reload
我有一个带有几个自动完成字段的搜索表单。
当页面第一次加载时,一切正常,但是如果我重新加载/按F5键,则即使没有人获得焦点,也将触发所有具有minLength:0的字段。
没有其他动作会导致此情况。
function autocompleter(searchfield, autocompletee) {
$(searchfield)
.autocomplete({
minLength: autocompletee.minLength,
source: autocompletee.array,
change: function(event, ui) {
if (!ui.item) {
event.target.value = "";
}
},
select: function (event, ui) {
var chosenWord = ui.item.label;
var searchKeyWord = {
"webformField": autocompletee.selected,
"searchString": chosenWord
};
$.ajax({
contentType: "application/json; charset=utf-8",
type: 'POST',
url: "MyHandler.ashx",
data: JSON.stringify(searchKeyWord),
});
var title = ui.item.label; //get the object title here
$(searchfield).val(title);
$(autocompletee.chosen).append("<asp:HyperLink href='#' class='myClass' runat='server' ID='" + chosenWord + "'>" + chosenWord + "</asp:HyperLink>"); //
$(searchfield).val("");
$(searchfield).blur();
return false;
}
}).focus(function() {
$(this).autocomplete("search", "");
});
}
$(document).ready(function() {
var myObject = {
array: window.myarray,
selected: "object_chosen",
chosen: "#object_chosen",
minLength: 0,
};
autocompleter('#inputField, myObject);
});
<input type="text" id="inputField" placeholder="Text" runat="server" clientidmode="Static" />
<asp:Panel ID="object_chosen" CssClass="chosen-tag-container" ClientIDMode="Static" runat="server">
<%-- links appear here--%>
</asp:Panel>
尝试这个
$(document).ready(function() {
var myObject = {
array: window.myarray,
selected: "object_chosen",
chosen: "#object_chosen",
minLength: 0,
};
autocompleter("#inputField", myObject); //Remove this because it's calling that function on page load
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.