bootstrap3-typeahead 自动补全

之前做的自动补全是用的jquery的autocomplete,今天发现一个很酷的自动补全插件! 

 

很酷的一个自动补全插件

http://twitter.github.io/typeahead.js

 

在bootstrap中使用typeahead插件,完成自动补全

 

数据源:

Local:数组

prefectch:json

remote等方式

 



 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

<!-- bootstrap -->
<link href="../../bootstrap-3.0.0/dist/css/bootstrap.min.css" rel="stylesheet" media="screen">

<!-- 需要额外的css样式覆盖bootstrap的样式,让dropdown列表好看些 -->
<link href="typeahead.css" rel="stylesheet">

<!-- typeahead需要1.9以上的jquery -->
<script src="jquery-10.0.2.js"></script>

<!-- typeahead -->
<script src="typeahead.min.js"></script>

<style>
body {
	padding: 50px; /*边距*/
}
input{
	font-size: 20px;
}
</style>
<script type="text/javascript">
	$(function(){
		//初始化typeahead
		$('input.typeahead').typeahead({               
			  name: 'countries',/*用来区分数据源,数据源可能有多个*/                                                          
			  local: ['Andorra', 'United Arab Emirates', 'Afghanistan', 'Anguilla'],  /*本地数据*/                               
			  limit: 10,
			  header: 'list of country:'/*结果集的标题*/
			});
	});
</script>
</head>
<body>
	<div style="text-align:left">
		<h3>Countries</h3>
		<p>Prefetches data, stores it in localStorage, and searches it on the client</p>
		<hr>
	</div>
	<div class="well well-lg">
		<!-- 自动补全框 -->
		<input type="text" class="typeahead" placeholder="country">
	</div>
</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值