我正在使用JQuery 1.11.1。我有一个自动完成过滤器,我这样设置......
<input type="text" id="stateFilter" placeholder="Select a State" /><img src="/myproject/resources/images/menu-arrow-closed.png" />
和JS是
states = $.map(list, convertListItem);
....
$("#stateFilter").autocomplete({source: states});
我的问题是,在某些情况下,我希望默认情况下选择其中一个选项(因此用户看到的第一件事不是&#34;选择状态&#34;而是名称被选中的州,例如&#34; Virginia&#34;)。我如何预先选择一个选项?设置&#34;值&#34;我的输入字段的属性不执行任何操作。
答案 0 :(得分:0)
尝试使用search
方法.autocomplete("search", "term")
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#tags" ).autocomplete({
source: availableTags
})
.autocomplete("search", "JavaScript");
$("ul.ui-autocomplete")
.find("li:contains(JavaScript)")
.trigger("click")
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
</body>