第五章 使用 Bootstrap Typeahead 组件(百度下拉效果)
推荐链接:http://www.cnblogs.com/haogj/p/3376874.html
UnderScore官网:http://underscorejs.org/
参考文档:http://www.css88.com/doc/underscore/
页面代码:
@{
ViewBag.Title = "Index";
}
<script src="Scripts/bootstrap-typeahead.js"></script>
<script src="Scripts/underscore-min.js"></script>
<div>
简单使用
<div style="margin: 10px 50px">
<label for="product_search">
Product Search:
</label>
<input id="product_search" type="text" data-provide="typeahead" data-source='["DATA1", "DATA2", "DATA3"]' />
</div>
使用脚本填充数据
<div style="margin: 10px 50px">
<label for="product_search">
Product Search:
</label>
<input id="product_search_js" type="text" data-provide="typeahead">
</div>
<script type="text/javascript">
$(document).ready(function ($) {
$.fn.typeahead.Constructor.prototype.blur = function () {
var that = this;
setTimeout(function () { that.hide() }, );
};
$('#product_search_js').typeahead({
source: function (query, process) {
return ["JS数据1", "JS数据2", "JS数据3"];
},
highlighter: function (item) {
return "==>" + item + "<==";
},
updater: function (item) {
console.log("'" + item + "' selected."); //浏览器控制台输出
$("#product_search").val(item);
return item;
}
});
})
</script>
支持 Ajax 获取数据
<div style="margin: 10px 50px">
<label for="product_search">
Product Search:
</label>
<input id="product_search_ajax" type="text" data-provide="typeahead">
</div>
<script type="text/javascript">
$('#product_search_ajax').typeahead({
source: function (query, process) {
var parameter = { query: query };
$.post('@Url.Action("AjaxService")', parameter, function (data) {
process(data);
});
}
});
</script>
使用对象数据
<div style="margin: 10px 50px">
<label for="product_search">
Product Search:
</label>
<input id="product_search_object" type="text" data-provide="typeahead">
</div>
<script type="text/javascript">
$(function () {
var products = [
{
id: ,
name: "object1",
price: 499.98
},
{
id: ,
name: "object2",
price: 134.99
},
{
id: ,
name: "object3",
price: 49.95
}
];
$('#product_search_object').typeahead({
source: function (query, process) {
var results = _.map(products, function (product) {
return product.name;
});
process(results);
},
highlighter: function (item) {
return "==>" + item + "<==";
},
updater: function (item) {
console.log("'" + item + "' selected.");
return item;
}
});
});
</script>
</div>
控制器
public ActionResult Index()
{
return View();
} public ActionResult AjaxService()
{
string query = "";
if (!string.IsNullOrWhiteSpace(Request["Query"]))
query = Request["Query"].ToString();
var data = ("AJAX1,AJAX2,AJAX3").Split(',');
return Json(data);
}
效果:
第五章 使用 Bootstrap Typeahead 组件(百度下拉效果)的更多相关文章
- 第六章 使用 Bootstrap Typeahead 组件(百度下拉效果)(续)
官方:http://twitter.github.io/typeahead.js/ 示例:http://twitter.github.io/typeahead.js/examples/(本文展示:Op ...
- Bootstrap <基础十二>下拉菜单(Dropdowns)
Bootstrap 下拉菜单.下拉菜单是可切换的,是以列表格式显示链接的上下文菜单.这可以通过与 下拉菜单(Dropdown) JavaScript 插件 的互动来实现. 如需使用下列菜单,只需要在 ...
- 【亲测好用!】shell批量采集百度下拉框关键词
[亲测好用!]shell批量采集百度下拉框关键词 SEO工具 方法 11个月前 (11-18) 2153浏览 3条评论 百度已收录 一直想写一篇用shell采集百度下拉框关键词的教程,个人感觉用 ...
- angular的跨域(angular百度下拉提示模拟)和angular选项卡
1.angular中$http的服务: $http.get(url,{params:{参数}}).success().error(); $http.post(url,{params:{参数}}).su ...
- chosen组件实现下拉框
chosen组件用于增强原生的select控件,使之有更好的用户体验.官方demo https://harvesthq.github.io/chosen/ 目前项目中碰到的使用,比如一个页面中有两个不 ...
- 仿百度下拉关键词,和关键词的小demo
自己做项目时用到的仿百度下拉关键词 代码: $(function(){ var oTxt = document.getElementById('search_text'); oTxt.onkeyup ...
- Bootstrap历练实例:下拉菜单插件方法的使用
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- vue的jsonp百度下拉菜单
通过vue的jsonp实现百度下拉菜单的请求,vue的版本是2.9.2 <!DOCTYPE html> <html lang="en"> <head& ...
- vue实现百度下拉框
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
随机推荐
- SarePoint Powershell Add user to Group
$FromGroupnames = "001总经理","010101管理本部" $ToGroupname = "test" $SPWeb = ...
- 如何通过PowerShell在Visual Studio的Post-build中预热SharePoint站点
问题现象 Visual Studio在开发SharePoint的时候,发布部署包后,首次打开及调试站点页面的时候会非常的慢 解决方案 使用PowerShell脚本,加载SharePoint插件后遍历所 ...
- android ButterKnife 解决重复findViewById
简介: 程序员都是懒惰的,不想写一大堆像下面这样的代码 class ExampleActivity extends Activity { TextView title; TextView subtit ...
- 关于android4.3 Intel X86 Atom System Image的下载
今天建立android4.3模拟器的时候发现没有android4.3 Intel X86 Atom System Image可选,打开android SDK Manager 于是希望重现选择下载安装, ...
- page resizing
<script type="text/javascript"> $(window).load(function () { var root; root = $(&quo ...
- android学习笔记 Service
Service(服务): 长期后台运行的没有界面的组件 android应用什么地方需要用到服务? 天气预报:后台的连接服务器的逻辑,每隔一段时间获取最新的天气信息.股票显示:后台的连接服务器的逻辑,每 ...
- Swift面向对象基础(中)——Swift中的方法
学习来自<极客学院> 1.定义方法需要在类型(枚举,结构体,类)里定义,不能独立定义,独立定义的是函数 2.方法要么属于该类型本身,要么是该类型的一个实例 3.不能独立执行方法,执行方法必 ...
- TreeSize工具介绍
TreeSize Professional 工具是一个功能强大且灵活方便的硬盘空间管理工具,能在 Windows 8/7/Vista/XP 或 Windows Server 2012年/2008年/2 ...
- jquery实践案例--验证手机号码
如果要做手机号的验证,那么我们需要知道手机号码的号段. 182 183 187 188 155 156 176 186 189 //移动运营商:170 移动: 2G号段(GSM):134-139.15 ...
- 烂泥:ubuntu安装KVM虚拟机管理virt-manager
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 打算学习KVM的图形界面管理器virt-manager,但是virt-manager只有linux系统的,没有windows下的.所以只能使用linux ...