jQuery自动完成在Firefox中运行良好,但在Chrome中则不然

jQuery autocomplete works fine in Firefox but not in Chrome

本文关键字:但在 Chrome 运行 Firefox jQuery      更新时间:2023-09-26

我在文本输入字段上有一个jQuery自动完成功能,它在Firefox中运行良好,但在Chrome中没有响应。这是该字段的脚本:

$(function () {
    var availableTags = [
        "La Plagne",
        "Geneva"
    ];
    $("#locationinput1, #locationinput2").autocomplete({
        source: availableTags,
        messages: {
            noResults: '',
            results: function () {}
        }
    });
});

您的代码在Chrome中运行良好。在<head>标记中是否有jQuery和jQuery UI,它们都位于自动完成脚本之上?

示例:

<script type="text/javascript" src="//code.jquery.com/jquery-2.0.2.js"></script>  
<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">
$(function () {
    var availableTags = [
        "La Plagne",
        "Geneva"
    ];
    $("#locationinput1, #locationinput2").autocomplete({
        source: availableTags,
        messages: {
            noResults: '',
            results: function () {}
        }
    });
});
</script>

JSFiddle-在Chrome 中工作

您的代码在Chrome中运行良好。你能告诉我们你使用的是哪个版本的Chrome吗?我使用的是41.0.2272.118 m版本,代码对我来说很有效。同时在控制台中检查是否出现任何javascript错误。如果它来了,那么首先解决这个错误。它需要解决所有javascript错误。我正在放置我尝试过的代码。你可以点击"运行代码段"来检查代码是如何工作的。

$(function () {
    var availableTags = [
        "La Plagne",
        "Geneva"
    ];
    $("#locationinput1, #locationinput2").autocomplete({
        source: availableTags,
        messages: {
            noResults: '',
            results: function () {}
        }
    });
});
<script type="text/javascript" src="http://code.jquery.com/jquery-2.0.2.js"></script>  
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<input id="locationinput1" type="text" name="origin" placeholder="From (Airport/Resort)"/>
<input id="locationinput2" type="text" name="destination" placeholder="To (Airport/Resort)"/>

相关文章: