Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery UI自动完成部分匹配_Jquery_Jquery Ui_Jquery Autocomplete - Fatal编程技术网

jQuery UI自动完成部分匹配

jQuery UI自动完成部分匹配,jquery,jquery-ui,jquery-autocomplete,Jquery,Jquery Ui,Jquery Autocomplete,我试图让jQueryUI只自动完成搜索字符串的前几个字母。我想我可以用jQueryUI做一件关键/价值的事情,但我不确定这是否适用 我有以下字符串: 只应搜索AGREE,而不应搜索字符串的其余部分AGREE是用户将搜索的文本代码 以下是我的简单代码: 只应搜索第一个单词AGREE和CONDO,而不搜索其余字符串。这是否可能/可行?如果只搜索标签,为什么不将标签放入数组中?我的解决方案是: <!doctype html> <html lang="en"> <hea

我试图让jQueryUI只自动完成搜索字符串的前几个字母。我想我可以用jQueryUI做一件关键/价值的事情,但我不确定这是否适用

我有以下字符串:

只应搜索
AGREE
,而不应搜索字符串的其余部分
AGREE
是用户将搜索的文本代码

以下是我的简单代码:


只应搜索第一个单词
AGREE
CONDO
,而不搜索其余字符串。这是否可能/可行?

如果只搜索标签,为什么不将标签放入数组中?

我的解决方案是:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>autocomplete demo</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
</head>
<body>
<label for="autocomplete">Select a programming language: </label>
<input id="autocomplete">
<script>
var tags = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ];
$( "#autocomplete" ).autocomplete({
source: function( request, response ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
response( $.grep( tags, function( item ){
return matcher.test( item );
}) );
}
});
</script>
</body>
</html>

自动完成演示
选择一种编程语言:
var标签=[“c++”、“java”、“php”、“coldfusion”、“javascript”、“asp”、“ruby”];
$(“#自动完成”)。自动完成({
来源:功能(请求、响应){
var matcher=newregexp(“^”+$.ui.autocomplete.escapeRegex(request.term),“i”);
响应($.grep(标记、函数(项)){
返回匹配器测试(项目);
}) );
}
});

Ref.(页面底部)

True,但我需要在文本框中自动填充其余文本。我的建议是在选择关键字后使用jQuery
append()
添加文本。您认为此页面底部的内容如何,“演示:示例:使用自定义源回调仅匹配术语的开头”您认为我可以使用它吗?听起来像我想做的…可以工作。或者您可以使用
keyup
事件,并使用if语句检查该文本框中的一个或多个特定值和
append()
基于此的附加文本。感谢您的回答。这非常有帮助,但我想我会使用我在上面链接的页面上的方法。我在下面发布了我的解决方案。可能重复。请查看答案。
var availableTags = [
            "AGREE Agreement by and between BLANK, in BLANK, of the county records.",
            "CONDO Covenants, conditions, restrictions, reservations, terms, provisions, easements, liens for assessments, options, powers of attorney and limitations on title as set forth in the Ohio Revised Code Chapter 5311, or as set forth in the Declaration of Condominium ownership and Bylaws as recorded in BLANK, as amended, plat BLANK, of the county records."
        ];

$( "#tags" ).autocomplete({
 source: availableTags
});
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>autocomplete demo</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
</head>
<body>
<label for="autocomplete">Select a programming language: </label>
<input id="autocomplete">
<script>
var tags = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ];
$( "#autocomplete" ).autocomplete({
source: function( request, response ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
response( $.grep( tags, function( item ){
return matcher.test( item );
}) );
}
});
</script>
</body>
</html>