BootStrap學習系列之Bootstrap Typeahead 組件實現(xiàn)百度下拉效果(續(xù))
接著上篇的內(nèi)容,在上篇給大家介紹了Bootstrap學習系列之使用 Bootstrap Typeahead 組件實現(xiàn)百度下拉效果
Bootstrap,來自 Twitter,是目前最受歡迎的前端框架。Bootstrap 是基于 HTML、CSS、JAVASCRIPT 的,它簡潔靈活,使得 Web 開發(fā)更加快捷。
官方:http://twitter.github.io/typeahead.js/
示例:http://twitter.github.io/typeahead.js/examples/(本文展示:Open Source Projects by Twitter)
項目源碼:https://github.com/twitter/typeahead.js(點擊Download ZIP下載typeahead.js-master.zip)
先給大家展示下效果圖:
1.實現(xiàn)
HTML
提示:examples.css為實例中的css文件
<link type="text/css" href="@Url.Content("~/Scripts/typeahead/examples.css")" rel="stylesheet"/> <script src="@Url.Content("~/Scripts/typeahead/typeahead.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/typeahead/hogan-2.0.0.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/typeahead/underscore-min.js")" type="text/javascript"></script> <div> <div style="margin: 10px 50px" class="col-md-3"> <div class="form-group example-twitter-oss"> <label class="col-md-4 control-label "> 姓名</label> <div class="col-md-7"> @Html.TextBox("InputName", "", new { @class = "inputName form-control", placeholder = "請輸入姓名" }) </div> </div> </div> @Html.Hidden("getInputName", Url.Action("GetInputName")) <script type="text/javascript"> $('.inputName').typeahead({ name: 'inputname', remote: $("#getInputName").val() + '/?query=%QUERY', template: ['<p class="repo-language">{{vipname}}</p>', '<p class="repo-name">{{name}}</p>', '<p class="repo-description">{{description}}</p>' ].join(''), limit: 10, engine: Hogan }); </script> </div>
控制器
#region 獲取姓名提示下拉 /// <summary> /// 獲取姓名提示下拉 /// </summary> /// <returns></returns> public ActionResult GetInputName(string query) { var list = new List<TypeaheadModel>(); if (!string.IsNullOrWhiteSpace(query)) { query = query.Trim(); foreach (var item in GetData()) { if (item.name.Contains(query)) { list.Add(item); } } } return Json(list, JsonRequestBehavior.AllowGet); } #endregion public List<TypeaheadModel> GetData() { List<TypeaheadModel> list = new List<TypeaheadModel>(); TypeaheadModel model = new TypeaheadModel(); for (int i = 0; i < 5; i++) { model = new TypeaheadModel(); model.description = "D"; model.vipname = "V"; model.name = "A" + i.ToString(); model.value = "A" + i.ToString();// list.Add(model); } for (int i = 3; i < 10; i++) { model = new TypeaheadModel(); model.description = ""; model.vipname = ""; model.name = "B" + i.ToString(); model.value = "B" + i.ToString(); list.Add(model); } return list; }
模型
public class TypeaheadModel { public string name { get; set; } public string vipname { get; set; } public string description { get; set; } /// <summary> /// 選中后文本框的值 /// </summary> public string value { get; set; } }
以上所述是小編給大家介紹的BootStrap學習系列之Bootstrap Typeahead 組件實現(xiàn)百度下拉效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
JS根據(jù)key值獲取URL中的參數(shù)值及把URL的參數(shù)轉(zhuǎn)換成json對象
本篇文章主要圍繞js url 參數(shù)值展開話題,js根據(jù)key值獲取url中的參數(shù)值,接著把url的參數(shù)轉(zhuǎn)換成json,感興趣的朋友一起來學習吧,本文寫的不好地方還望多多指出批評建議2015-08-08js print打印網(wǎng)頁指定區(qū)域內(nèi)容的簡單實例
下面小編就為大家?guī)硪黄猨s print打印網(wǎng)頁指定區(qū)域內(nèi)容的簡單實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11100多個基礎(chǔ)常用JS函數(shù)和語法集合大全
本文將介紹100多個基礎(chǔ)常用JS函數(shù)和語法,具有很好的參考價值,下面跟著小編一起來看下吧2017-02-02JavaScript ES6解構(gòu)運算符的理解和運用
在ES6屬性中新增了兩個屬性,分別是解構(gòu)和…運算符,下面這篇文章主要給大家介紹了關(guān)于JavaScript ES6解構(gòu)運算符的理解和運用,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下2021-10-10