twitter-bootstrap 引导文本框自动完成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41845177/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bootstrap textbox autocomplete
提问by KiRa
I am using this Bootstrapas my GUI.
我使用这个Bootstrap作为我的 GUI。
I've seen this LINKrelated to my problem. But when I try the code from the @KyleMitI have an error in my console. I got this Uncaught TypeError: $(...).autocomplete is not a function
我已经看到这个LINK与我的问题有关。但是,当我尝试使用 代码时@KyleMit,我的控制台中出现错误。我懂了Uncaught TypeError: $(...).autocomplete is not a function
Current Code
当前代码
$(".autocomplete").autocomplete({
source: "/Controller/Action",
minLength: 1,
select: function (event, ui) {
if (ui.item) {
$(".autocomplete").val(ui.item.value);
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="form-group">
<label>Languages</label>
<input class="form-control autocomplete" placeholder="Enter A" />
</div>
</div>
回答by Rahul
Check this basic example of jquery autocomplete,
检查这个 jquery 自动完成的基本示例,
JS CODE,
JS代码,
$( 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
});
} );
Your html,
你的html,
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
Include following code in your head tag,
在您的 head 标签中包含以下代码,
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
You can find jsfiddlehere.
你可以在这里找到jsfiddle。

