这是我的代码:
<script type="text/javascript" src="{THEME}/js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="{THEME}/js/jquery.form.min.js"></script>
<script type="text/javascript" src="{THEME}/js/jcarousellite_1.0.1.pack.js"></script>
<script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(function() {
var availableTags = ["Canada", "United States", "United Kingdom", "Russia", "Iran", "Sweden", "France"];
$("#searchQuery").autocomplete(availableTags);
});
});
</script>
并且容器中的输入向左浮动。
<input type="text" placeholder="Your Query" id="searchQuery" />
答案 0 :(得分:0)
您不应该简单地将数组传递给.autocomplete()
方法。您应该使用source
选项指定它是来源,如下所示:
$(document).ready(function() {
var availableTags = ["Canada", "United States", "United Kingdom", "Russia", "Iran", "Sweden", "France"];
$("#searchQuery").autocomplete({
source: availableTags
});
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<input type="text" placeholder="Your Query" id="searchQuery" />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
旁注:$(document).ready(function() {})
和$(function() {})
相同。你只需要其中一个。后者是前者的简写。