在我的应用程序中,我在该扩展器中添加了 ajax 自动完成扩展器,我使用了“OnClientPopulated”事件,对于该事件,我在 javascript 中编写了一个函数,它适用于 IE、Chrome、Safari 但不适用于 firefox,因为该事件无法在 firefox 中触发,以下我在那里写的代码:
<ajax:AutoCompleteExtender OnClientPopulated="getSearch_Populated" ID="AutoCompleteExtenderSearch"
runat="server" TargetControlID="txtSearchbox" MinimumPrefixLength="1" Enabled="true"
EnableCaching="true" CompletionSetCount="12" CompletionInterval="1000" ServiceMethod="GetAppNames"
ServicePath="~/AutoComplete.asmx" DelimiterCharacters="" UseContextKey="true"
CompletionListCssClass="AutoExtender" CompletionListHighlightedItemCssClass="AutoExtenderHighlight"
CompletionListItemCssClass=".AutoExtenderList" OnClientItemSelected="selected_Search">
</ajax:AutoCompleteExtender>
JavaScript:
function getSearch_Populated(sender, e) {
var searchList = sender.get_completionList().childNodes;
var searchText = sender.get_element().value;
for (var i = 0; i < searchList.length; i++) {
var search = searchList[i];
var searchValueArray = (search._value).split("|");
var searchId = searchValueArray[0];
var searchUrl = searchValueArray[1];
var link = document.createElement('a');
var href = document.createAttribute('href');
link.setAttribute('href', searchUrl);
link.innerText = searchId;
search.appendChild(link);
}
}