首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Bootstrap Typeahead.js

Bootstrap Typeahead.js
EN

Stack Overflow用户
提问于 2013-06-18 03:39:47
回答 3查看 13K关注 0票数 2

我一直在尝试让bootstrap typeahead工作,但没有任何运气。我已经粘贴了我拥有的代码。我有参考Jquery-1.9.1和typeahead.js。我做错了什么?非常感谢您的帮助!谢谢。

代码语言:javascript
复制
<%@ 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>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 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

票数 4
EN

Stack Overflow用户

发布于 2013-06-18 04:01:04

我希望这是你所期望的。下面是带有必要依赖项的完整代码try。

代码语言:javascript
复制
<!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>
票数 1
EN

Stack Overflow用户

发布于 2016-09-30 14:06:50

添加了两个功能的Type文件:

  1. 类型空格栏显示所有自动完成数据的
  2. 如果您提供带空格的数据也可以排序和显示数据的

将Lookup函数更改为:

代码语言:javascript
复制
 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();
    }
},
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17155439

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档