Unterstrich : : http: //underscorejs.org/
参考文档 : http: //www.css88.com/doc/underscore/
页面代码 :
@{Viewbag.title = "index";} <script src = "scripts/bootstrap-typeahead.js"> </script> <script src = "scripts/Undercore-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 für = "product_search"> Produktsuche: </label> <input id = "product_search_js" type = "text" data-provide = "typeAeAwhead"> </div> <script type = "text/javaScript"> $ (Dokument). () {var that = this; setTimeout (function () {that.hide ()}, 250);}; $ ('#product_search_js'). typeAehead ({Quelle: Funktion (Abfrage, Prozess) {return ["js 数据 1", "js 数据 2", {Js 数据 3 "}; "<==";}, updater: function (item) {console.log ("'" + item + "' ausgewählt.");支持 Ajax 获取数据
<div style = "margin: 10px 50px"> <label für = "product_search"> Produktsuche: </label> <input id = "product_search_ajax" type = "text" data-provide = "typeAahead"> </div> <script type = "text/javaScript"> $ ('#produeaD_SEARD_SEACH |). {Abfrage: Abfrage}; $. post ('@url.action ("ajaxService")', Parameter, Funktion (Daten) {prozess (Daten);});}}); </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: 0,name: "object1",price: 499.98},{id: 1, Name: "Object2", Preis: 134,99}, {ID: 2, Name: "Object3", Preis: 49,95}]; "==>" + item + "<==";}, updater: function (item) {console.log ("'" + item + "' ausgewählt.");控制器
public actionResult index () {return view ();} public actionResult ajaxService () {String query = ""; if (! String.IsnullorwhITespace (Request ["Query"])) query = requery ["Query"]. ToString ();效果图展示如下 :
下面继续给大家介绍 Bootstrap 学习系列之 Bootstrap TypeAhehead 组件实现百度下拉效果 (续)
以上所述是小编给大家介绍的 Bootstrap 学习系列之使用 Bootstrap -TypeAdhead 组件实现百度下拉效果 , 希望对大家有所帮助 , 如果大家有任何疑问请给我留言 , 小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持! 小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持! 小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!