gpt4 book ai didi

c# - 页面重新加载时触发自动完成

转载 作者:行者123 更新时间:2023-11-28 08:10:32 34 4
gpt4 key购买 nike

我有一个带有几个自动完成字段的搜索表单。

当页面第一次加载时,一切都运行良好,但如果我重新加载/按 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
});

关于c# - 页面重新加载时触发自动完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24278730/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com