我一直在尝试让bootstrap typeahead工作,但没有任何运气。我已经粘贴了我拥有的代码。我有参考Jquery-1.9.1和typeahead.js。我做错了什么?非常感谢您的帮助!谢谢。
<%@ 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>发布于 2013-06-18 04:01:36
看起来你把typeahead.js (推特)和Twitter Bootstrap's Typeahead feature搞混了
您正在包含typeahead.js的库
<script src="Scripts/typeahead.js-master/src/typeahead.js"></script>
但试着像Twitter Bootstrap的typeahead功能一样使用它。
如果您想要使用当前代码,请确保包含Twitter Bootstrap库:
<script type="text/javascript" src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
下面是一个例子:jsFiddle
发布于 2013-06-18 04:01:04
我希望这是你所期望的。下面是带有必要依赖项的完整代码try。
<!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>发布于 2016-09-30 14:06:50
添加了两个功能的Type文件:
将Lookup函数更改为:
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();
}
},https://stackoverflow.com/questions/17155439
复制相似问题