文本字段 jquery 自动完成 - 只允许在自动完成选项内提交
我正在我的代码中寻求帮助,仅在指定的数据数组中允许自动完成。因此,只允许输入自动完成数组内的数据。不知道在哪里执行此操作。这是我的代码。有人可以建议吗?
$(document).ready(function () {
var data = ["ActionScript","AppleScript","Asp","BASIC","C","C++","iran","Scheme"];
$("#autocomplete").autocomplete(data);
});
$('input#autocomplete').result(function (event, data, formatted) {
$("#result").html(!data ? "No match found!" : "Selected: " + formatted);
}).keyup(function () {
$(this).search();
$(this).css("background-color","#D6D6FF");
});
} catch (e) { }
});
I am looking for help in my code that allows an autocomplete, only within a specified data array. So only data within the auto complete array is allowed to be entered. Not sure where to do that .Here is my code. Can anyone suggest ??
$(document).ready(function () {
var data = ["ActionScript","AppleScript","Asp","BASIC","C","C++","iran","Scheme"];
$("#autocomplete").autocomplete(data);
});
$('input#autocomplete').result(function (event, data, formatted) {
$("#result").html(!data ? "No match found!" : "Selected: " + formatted);
}).keyup(function () {
$(this).search();
$(this).css("background-color","#D6D6FF");
});
} catch (e) { }
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用
mustMatch
选项 (docs):示例: http://jsfiddle.net/prCsm/
作为旁注,该插件已被弃用,取而代之的是 jQueryUI 版本。
Try the
mustMatch
option (docs):Example: http://jsfiddle.net/prCsm/
As a side note, this plugin has been deprecated in favor of the jQueryUI version.
您可以在用户选择特定值后禁用输入字段。请参阅示例代码
示例中的第 6 行:
You can simply disable the input field after the user selected a specific value. see line 6 in example code
example:
我执行以下操作: -
如果为 true,则选择是好的,否则选择是不好的,并且您可以将焦点返回到输入字段。
I do the following:-
If it is true the selection is good other wise it is bad and you can return focus to the input field.