[英]Bootstrap Typeahead.js
I have been trying to get the bootstrap typeahead to work, with no luck whatsoever. 我一直在尝试使引导程序正常工作,但没有任何运气。 I have pasted the code I have.
我已经粘贴了我的代码。 I have reference Jquery-1.9.1 and typeahead.js.
我参考了Jquery-1.9.1和typeahead.js。 What am I doing wrong?
我究竟做错了什么? Your help is much appreciated!
非常感谢您的帮助! Thanks.
谢谢。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<script src="Scripts/typeahead.js-master/test/vendor/jquery-1.9.1.js"></script>
<script src="Scripts/typeahead.js-master/src/typeahead.js"></script>
<title></title>
</head>
<body>
<form>
<div>
<input type="text" data-provide="typeahead" autocomplete="off" data-source='["arizona","alaska"]' />
</div>
</form>
</body>
</html>
It looks like you're getting confused between typeahead.js (by Twitter) and Twitter Bootstrap's Typeahead feature 看来您对typeahead.js (由Twitter 发起 )和Twitter Bootstrap的Typeahead功能感到困惑
You're including the library for typeahead.js 您包括typeahead.js的库
<script src="Scripts/typeahead.js-master/src/typeahead.js"></script>
but trying to use it like Twitter Bootstrap's typeahead feature. 但尝试像Twitter Bootstrap的预输入功能一样使用它。
Make sure you're including the Twitter Bootstrap library, if you want to use your current code: 如果要使用当前代码,请确保包含Twitter Bootstrap库:
<script type="text/javascript" src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
I hope this is what you expection. 我希望这是您的期望。 Here is the complete code try with necessary dependencies.
这是带有必要依赖项的完整代码尝试。
<!DOCTYPE html>
<html>
<head>
<title>Member</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
<div class="well">
<input type="text" class="span3" id="search" data-provide="typeahead" data-items="4" />
</div>
<script>
var subjects = ['PHP', 'MySQL', 'SQL', 'PostgreSQL', 'HTML', 'CSS', 'HTML5', 'CSS3', 'JSON'];
$('#search').typeahead({source: subjects})
</script>
</body>
</html>
The Type head File with add two features: Type头文件添加两个功能:
Change The Lookup Function This: 更改查找功能,这:
lookup: function (event) {
var that = this,
items;
if (that.ajax) {
that.ajaxer();
}
else if (($.trim(that.$element.val())) == "") {
that.query = that.$element.val();
if (!that.query) {
return that.shown ? that.hide() : that;
}
items = that.source;
if (!items || !items.length) {
return that.shown ? that.hide() : that;
}
return that.render(items.slice(0, that.options.items)).show();
}
else {
that.query = $.trim(that.$element.val());
if (!that.query) {
return that.shown ? that.hide() : that;
}
items = that.grepper(that.source);
if (!items || !items.length) {
return that.shown ? that.hide() : that;
}
return that.render(items.slice(0, that.options.items)).show();
}
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.