【发布时间】:2019-07-11 10:30:50
【问题描述】:
我知道同样的问题发布在:Always show a specific choice in jQuery Autocomplete even if it doesn't match input
问题是当使用上述问题中建议的打开功能作为解决方案时,仅当自动完成列表中有匹配项时才会触发该事件。因此,当用户在搜索框中输入时,并不总是显示特定的选择。
https://jsfiddle.net/u1jwz6s4/
<html lang="en">
<head>
<meta charset="utf-8">
<title>autocomplete demo</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<label for="autocomplete">Select a programming language: </label>
<input id="autocomplete">
</body>
</html>
$( "#autocomplete" ).autocomplete({
source: [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ],
open: function(){
$('.ui-autocomplete').prepend("search by keyword")
},
});
我想始终在最顶部显示“搜索为关键字”作为选项,无论用户在搜索框中输入时是否有匹配的字符串。目前,“搜索为关键字”仅在找到匹配字符串时显示在顶部。另外,是否有使“搜索为关键字”成为搜索表单中的可点击事件?请参阅 jsfiddle 以了解我所描述的内容。
【问题讨论】:
-
你能举例说明一下吗
标签: javascript jquery jquery-ui autocomplete