我在文本输入上使用 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 );
}; });