使用Bootstrap Typeahead 组件:

Bootstrap 中的 Typeahead 组件就是通常所说的自动完成 AutoComplete,自动填充。

效果如图所示:

实现方式:

1、引入Bootstrap的相关 Js:

<link href="${pageContext.request.contextPath}/static/bootstrap-3.3.4-dist/css/bootstrap.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/static/bootstrap-3.3.4-dist/js/bootstrap.min.js"></script>

2、引入Typeahead组件:

<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery_autocomplete/bootstrap-typeahead.js"></script>

3、html:

<input type="text" class="form-control"  id="select_company" data-provide="typeahead" data-items="4" placeholder="请输入企业名称">

4、js , 数据源有多种写法,这里以数组作为范例

$(function() {

  var enterprise = [];
  $.ajax({
    url : '${pageContext.request.contextPath}/dailycheck/getAllCompany',
    type : 'POST',
    dataType : 'JSON',
    success : function(data) {
      for (var i = 0; i < data.length; i++) {
        enterprise[i] = data[i].companyName;
      }
    }
  });

  $("#companyName").typeahead({
    source : enterprise
  });

});

使用Jquery autocomplete组件:

1、引入Jquery autocomplete组件:详情可访问http://jqueryui.com/autocomplete/  官方网址

<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery_autocomplete/jquery.autocomplete.min.js"></script>
<script src="${pageContext.request.contextPath}/static/jquery-ui/ui/jquery.ui.core.js"></script>
<script src="${pageContext.request.contextPath}/static/jquery-ui/ui/jquery.ui.widget.js"></script>
<script src="${pageContext.request.contextPath}/static/jquery-ui/ui/jquery.ui.tabs.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/jquery-ui/themes/base/jquery.ui.all.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/jquery_autocomplete/jquery.autocomplete.css" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/jquery-ui/demos.css">

2、html:

<input type="text"  id="select_company" placeholder="请输入企业名称">

3、js

$(function() {
  var enterprise = [];
  $.ajax({
    url : '${pageContext.request.contextPath}/dailycheck/getAllCompany',
    type : 'POST',
    dataType : 'JSON',
    success : function(data) {
      for (var i = 0; i < data.length; i++) {
        enterprise[i] = data[i].companyName;
      }
    }
  });

  $('#select_company').autocomplete({
    source : enterprise
  });

 
});

Bootstrap Typeahead/Jquery autocomplete自动补全的更多相关文章

  1. jQuery AutoComplete 自动补全

    jQuery.AutoComplete是一个基于jQuery的自动补全插件.借助于jQuery优秀的跨浏览器特性,可以兼容Chrome/IE/Firefox/Opera/Safari等多种浏览器. 特 ...

  2. jquery.autocomplete自动补全功能

    项目实例: 一:js //SupplierAutoComplete.js $().ready(function () { $("#txtSupplier").autocomplet ...

  3. jquery autocomplete自动补全

    简单用法: $(function(){ var data = "the People's Republic of China".split(" "); $(&q ...

  4. Autocomplete 自动补全(Webform实战篇)

    开篇语 因为项目中需要用到一个自动补全的功能,功能描述: 需求一:新增收件人的时候,自动下拉显示出数据库中所有的收件人信息(显示的信息包括:姓名-收件地址-联系方式) 需求二:选中一个值得时候,分别赋 ...

  5. jquery实现自动补全邮箱地址

    开始做的邮箱补全代码 //检查email邮箱 function isEmail(str) { if (str.indexOf("@") > 0) { return true; ...

  6. angular-ui-bootstrap typeahead 智能提示 自动补全 获取焦点不触发问题的解决

    项目中有一处使用了angular-ui-bootstrap中的typeahead来实现输入框智能提示语自动化补全的功能,存在一个bug, 即输入文字后,当再次点击文本框,其获取焦点后并不会触发智能提示 ...

  7. Pig autocomplete 自动补全

    在pig的grunt环境下,按TAB键可以自动补全命令,用户可以添加自己的补全信息. 在conf目录下创建autocomplete文件,添加如下内容: hdfs://vm1:8020/   在grun ...

  8. jquery.autocomplete自动补齐和自定义格式

    1.简单的下拉自动补齐,可以使用本地或远程数据源 <input name="autoTag" id="autoTag" /> var source ...

  9. jQuery邮箱自动补全代码

    JScript 代码   复制 (function($){ $.fn.emailMatch= function(settings){ var defaultSettings = { emailTip: ...

随机推荐

  1. ACM 蛇形填数

    蛇形填数 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为:10 11 12 19 16 1 ...

  2. POJ 1279 Art Gallery(半平面交)

    题目链接 回忆了一下,半平面交,整理了一下模版. #include <cstdio> #include <cstring> #include <string> #i ...

  3. 【hdu2795】Billboard

    Problem Description At the entrance to the university, there is a huge rectangular billboard of size ...

  4. 【bzoj2179】FFT快速傅立叶 FFT模板

    2016-06-01  09:34:54 很久很久很久以前写的了... 今天又比较了一下效率,貌似手写复数要快很多. 贴一下模板: #include<iostream> #include& ...

  5. iphone H5 input type="search" 不显示搜索 解决办法

    H5 input type="search" 不显示搜索 解决办法 H5 input type="search" 不显示搜索 解决方法 在IOS(ipad iP ...

  6. SDCycleScrollView 滚动视图的使用(广告)

    github库链接https://github.com/gsdios/SDCycleScrollView 无限循环自动图片轮播器(一步设置即可使用) // 网络加载图片的轮播器 cycleScroll ...

  7. Android常用功能代码块

    1.设置activity无标题,全屏 // 设置为无标题栏 requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置为全屏模式 getWindow(). ...

  8. [LintCode] LRU Cache 缓存器

    Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...

  9. android获取系统通讯录

    package com.example.administrator.yunphone.View; import android.app.Fragment; import android.databas ...

  10. Js文字特效—文字段逐个变色循环

    自己用来练习的,附上详细注释,如果有和我一样喜欢并想要学习Dom特效创作的朋友,推荐先系统了解Javascript中Html Dom Object部分的内容,包括常用方法及属性. <!DOCTY ...