【发布时间】:2011-12-09 19:12:21
【问题描述】:
我在文本输入上使用 jQuery 自动完成小部件来替换选择下拉列表。当用户单击文本框时,会打开建议下拉菜单。我的解决方案在 FireFox 中运行良好,但在 Internet Explorer 8 中出现了一些故障。在 Internet Explorer 中,当从建议下拉列表中选择项目时,建议列表消失,然后重新出现一秒钟。我不知道如何防止这种情况。
我正在使用: (jquery) jquery-1.6.4.min.js (jquery UI) jquery-ui-1.8.16.custom.min.js
代码如下
<input type="text" style="width:200px;" id="txtPosTypeS" value="" />
var RegTempList = [
{ label: "Auxiliary Monthly Trust", value: 1000},
{ label: "Auxiliary Monthly Operating", value: 1001},
{ label: "Auxiliary Hourly Trust", value: 1002},
{ label: "Auxiliary Hourly Operating", value: 1003}]
$().ready(function() {
$('#txtPosTypeS').autocomplete({
minLength: 0,
source: RegTempList,
delay: 0,
focus: function( event, ui ) {
$(this).val( ui.item.label );
return false;
},
select: function( event, ui ) {
$(this).blur();
$(this).val( ui.item.label );
return false;
},
change: function (event, ui) {
//if the value of the textbox does not match a suggestion, clear its value
if ($(".ui-autocomplete li:textEquals('" + $(this).val() + "')").size() == 0) {
$(this).val('');
$('#hidPositionType').val('');
}
},
close: function(event, ui) {
$(this).blur();
return false;
}
})
.focus(function(){
$(this).autocomplete('search','');
})
.data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.label + "</a>" )
.appendTo( ul );
}; });
【问题讨论】:
-
你不见了:
$.expr[':'].textEquals = function(a, i, m) { return $(a).text().match("^" + m[3] + "$"); }; -
您在数组末尾缺少分号。
标签: jquery jquery-ui jquery-autocomplete