The*_*ack 2 javascript jquery jquery-ui jquery-ui-autocomplete
是否有可能使用jQuery自动完成,以便如果有'source:'值可用,但它们与您输入的内容不匹配,那么只需一次显示所有源?
IE,给定以下代码,如果我输入"菠萝",你如何显示所有编程语言而不是它们?
<script>
$(function() {
var availableTags = [
"JavaScript",
"Perl",
"PHP",
"Python",
"Ruby"
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
<input type="text" id="tags" />
Run Code Online (Sandbox Code Playgroud)
将该source属性与自定义函数一起使用.下面显示的自定义函数模仿自动完成原始行为,在可用标记内搜索键入的文本作为子字符串.如果未找到匹配项,则返回所有可用标记.
$(function() {
var availableTags = [
"JavaScript",
"Perl",
"PHP",
"Python",
"Ruby"
];
$("#tags").autocomplete({
source: function(request, response) {
var term = request.term.toLowerCase();
var matchingTags = $.grep(availableTags, function(tag) {
return tag.toLowerCase().indexOf(term) >= 0;
});
response(matchingTags.length ? matchingTags : availableTags);
}
});
});?
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2768 次 |
| 最近记录: |