JQuery Auto Complete替代Select Drop Down

我在文本输入上使用jQuery自动完成小部件来替换选择下拉列表。 当用户点击文本框时,会打开建议下拉列表。 我的解决方案在FireFox中工作得很好但在Internet Explorer 8中有点故障。在Internet Explorer中,当从建议下拉列表中选择项目时,建议列表消失,然后重新显示一小段时间。 我不知道如何防止这种情况。

我正在使用:(jquery)jquery-1.6.4.min.js(jquery UI)jquery-ui-1.8.16.custom.min.js

代码如下

 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 $( "
  • " ) .data( "item.autocomplete", item ) .append( "" + item.label + "" ) .appendTo( ul ); }; });

    使用IE8和jsfiddle,更改函数中的textEquals上存在脚本错误。 删除更改function,修复问题。

    把它扔进jsFiddle,这里是链接。

    http://jsfiddle.net/BDd9H/

    此外,更新文本框宽度,以便文本不跳转。