Twitter bootstrap 3 bootstrap3typeahead.js:我在哪里可以找到工作示例代码?
我正在寻找一个typeahead的工作示例。我想使用它,但我找不到一个可以与Bootstrap3一起使用的代码片段。我想在这里自动完成。如果你有一些链接,谢谢。使用Bootsrap很难,因为exp的字体: 正式文件 本地方式Twitter bootstrap 3 bootstrap3typeahead.js:我在哪里可以找到工作示例代码?,twitter-bootstrap-3,typeahead.js,Twitter Bootstrap 3,Typeahead.js,我正在寻找一个typeahead的工作示例。我想使用它,但我找不到一个可以与Bootstrap3一起使用的代码片段。我想在这里自动完成。如果你有一些链接,谢谢。使用Bootsrap很难,因为exp的字体: 正式文件 本地方式 你能说得更具体些吗?任何澄清您的请求的功能或内容。谢谢您的回复。我已经试过了,但自动完成不起作用。是的,解决这个问题的最好方法是查看Chrome F12中的exp控制台。存在:未捕获错误:Bootstrap的JavaScript需要jQuery Bootstrap。min.
你能说得更具体些吗?任何澄清您的请求的功能或内容。谢谢您的回复。我已经试过了,但自动完成不起作用。是的,解决这个问题的最好方法是查看Chrome F12中的exp控制台。存在:未捕获错误:Bootstrap的JavaScript需要jQuery Bootstrap。min.js:6 XMLHttpRequest无法加载。请求的资源上不存在“Access Control Allow Origin”标头。因此不允许访问源代码“”。再次感谢您的帮助。我正在尝试完整的文档,但它不起作用。我在chrome调试控制台上收到一个错误消息。警告:显示临时标题。我在问题上添加了一个屏幕截图。好朋友,问题出在你这边,请尝试在Chrome中禁用扩展,或者(更好的方法)正如我在给asnwerThanks VeeeneX写的信中所说,我终于明白发生了什么。如果我错了,请纠正我。当我们使用预取时。在页面加载时,发送XMLHttpRequest以获取数据并将其存储在本地存储器中。数据将用于自动完成。但正如我们所知,XMLHttpRequest受同源策略的约束。要发送XMLHttpRequest,网页必须与响应请求的服务器应用位于同一服务器上。因此,我已将预回迁url更改为本地路径。这是一件很有魅力的工作。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" media="screen">
<style>
html {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 18px;
line-height: 1.2;
color: #333;
}
.tt-dropdown-menu{
text-align: left;
}
.typeahead,
.tt-query,
.tt-hint {
padding: 8px 12px;
font-size: 24px;
outline: none;
}
.typeahead {
background-color: #fff;
}
.tt-query {
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
}
.tt-hint {
color: #999
}
.tt-dropdown-menu {
width: 422px;
margin-top: 12px;
padding: 8px 0;
background-color: #fff;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.2);
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
-webkit-box-shadow: 0 5px 10px rgba(0,0,0,.2);
-moz-box-shadow: 0 5px 10px rgba(0,0,0,.2);
box-shadow: 0 5px 10px rgba(0,0,0,.2);
}
.tt-suggestion {
padding: 3px 20px;
font-size: 18px;
line-height: 24px;
}
.tt-suggestion.tt-cursor {
color: #fff;
background-color: #0097cf;
}
.tt-suggestion p {
margin: 0;
}
</style>
</head>
<body>
<div class="container">
<div class="countries"> <!-- This is a .countries in that examples.js -->
<div class="demo">
<input class="typeahead form-control" type="text" placeholder="Countries" autocomplete="off" spellcheck="false" dir="auto" > <!-- This is a typehead class in that js-->
<input class="typeahead form-control" type="text" disabled="" autocomplete="off" spellcheck="false" style="visibility: hidden; ">
<pre aria-hidden="true" style="position: absolute; visibility: hidden; white-space: nowrap; font-size: 24px; font-style: normal; font-variant: normal; font-weight: 400; word-spacing: 0px; letter-spacing: 0px; text-indent: 0px; text-rendering: auto; text-transform: none;">
</pre>
<span class="tt-dropdown-menu" style="position: absolute; top: 100%; left: 0px; z-index: 100; display: none;">
<div class="tt-dataset-countries"></div>
</span>
</div>
</div>
<script src="./typeahead.bundle.js"></script>
<script src="./examples.js"></script>
</div>
</body>
</html>
$(document).ready(function() {
var numbers;
var countries = new Bloodhound({
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.name); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
prefetch: {
url: './countries.json',
filter: function(list) {
return $.map(list, function(country) { return { name: country }; });
}
}
});
countries.initialize();
$('.countries .typeahead').typeahead(null, {
name: 'countries',
displayKey: 'name',
source: countries.ttAdapter()
});
});
$(document).ready(function() {
var numbers;
var countries = new Bloodhound({
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.name); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
local: [
{ name: 'Andorra' },
{ name: 'United Arab Emirates' },
{ name: 'Afghanistan'},
{ name: 'Antigua and Barbuda'},
{ name: 'Anguilla'},
]
});
countries.initialize();
$('.countries .typeahead').typeahead(null, {
displayKey: 'name',
source: countries.ttAdapter()
});
});