有效值的JQuery自动完成下拉在IE9上不起作用

时间:2012-01-15 23:54:22

标签: jquery internet-explorer-9 jquery-autocomplete

我在另一个问题上找到了以下信息,我改进了自动完成功能,以便在字段获得焦点时显示可用值列表。这在Firefox和Chrome中运行得非常好,但在IE9上则不行。

我创建了一个代码示例here。如果您使用Firefox或Chrome打开它,它会起作用,但如果您使用IE9打开它,则无效。为什么呢?

任何人都有解决此问题的方法吗?

更新

Description of the issue

以上图片适用于FireFox。在字段中设置光标时,将显示可用值列表。使用IE9时不显示此列表。

2 个答案:

答案 0 :(得分:1)

您的if条件应该是这样的,使用==代替使用===

if (this.value == "") {
    $(this).autocomplete("search", "");
}

==等于(仅限值)

===完全等于(值和类型)


修改

只需评论console.log(this.value);,然后就可以了。

http://jsfiddle.net/PEhdP/4/

答案 1 :(得分:-2)

$(function() { var cache = {}, lastXhr; $( "#birds" ).autocomplete({ minLength: 2, source: function( request, response ) { var term = request.term; if ( term in cache ) { response( cache[ term ] ); return; } lastXhr = $.getJSON( "search.php", request, function( data, status, xhr ) { cache[ term ] = data; if ( xhr === lastXhr ) { response( data ); } }); } }); });

//请尝试这个