Подчеркивается 官网 : 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"> Поиск продукта: </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"> Поиск продукта: </label> <input Id = "product_search_js" type = "text" data-provide = "typeaehead"> </div> <script-type = "text/javascript"> $ (document). function ($) ($. = function () {var that = this; settimeout (function () {this.hide ()}, 250);}; $ ('#product_search_js'). Typeahead ({Source: function (Query, Process) {return ["js 数据 1", "js 数据 2", "js 数据 3"];}, Highlight: item) {stect intem) {stect item) {stem) {retury "= stem)". "<==";}, Updater: function (item) {console.log ("'" + item + "' 'Selected.");支持 Ajax 获取数据
<div style = "margin: 10px 50px"> <label for = "product_search"> Поиск продукта: </label> <input id = "product_search_ajax" type = "text" data-provide = "typeaead"> </div> <script type = "text/javascript"> $ ('#product_search_ajax'). Parameter = {Query: Query}; $. post ('@url.action ("ajaxservice")', parameter, function (data) {process (data);});}}); </script>使用对象数据
<div style = "margin: 10px 50px"> <label for = "product_search"> Поиск продукта: </label> <input Id = "product_search_object" type = "text" provide = "typeaehead"> </div> <script type = "text/javascript"> $ (function () {var products = [ud: vame: "object1", gavascript "> $ (function () {var = [id: 0, name:", nation1 ". 499.98}, {id: 1, name: "object2", цена: 134.99}, {id: 2, name: "object3", цена: 49.95}]; $ ('#product_search_object'). Typeahead ({source: function (Query, process) {var result = _map (product). Product.name;}); Process (Results);}, Highlighter: function (item) {return "==>" + item + "<==";}, обновления: function (item) {console.log ("'" + item + "' 'Выбрано."); return item;});}); </script> </div>控制器
public actionResult index () {return view ();} public actionResult ajaxService () {string Query = ""; if (! String.isnullorWhitSpace (запрос ["Query"])) Query = запрос ["Query"]. ToString (); var data = ("ajax1, ajax2, ajax3"). Json (data);}效果图展示如下 :
下面继续给大家介绍 Bootstrap 学习系列之 Bootstrap typeahead 组件实现百度下拉效果 (续)
以上所述是小编给大家介绍的 Bootstrap 学习系列之使用 Bootstrap Typeaead 组件实现百度下拉效果 希望对大家有所帮助 希望对大家有所帮助 如果大家有任何疑问请给我留言 , 小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持! 小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持! 小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!