在ASP.NET MVC中使用Twitter Typehead

时间:2013-12-19 20:40:41

标签: asp.net typeahead.js twitter-typeahead

在Index.cshtml中,我有以下代码:

@{
ViewBag.Title = "Home Page";

}

 <script type="text/javascript" src="http://twitter.github.io/typeahead.js/js/jquery-1.9.1.min.js"></script>
 <script type="text/javascript" src="http://twitter.github.io/typeahead.js/releases/latest/typeahead.js"></script>
 <script type="text/javascript" src="http://twitter.github.io/typeahead.js/js/hogan-2.0.0.js"></script>
 <script src="../../Content/twitter/typeahead.min.js" type="text/javascript"></script>

 <script type="text/javascript">
      $('input.countries').typeahead({
           name: 'countries',
           local: ["Unites States", "Mexico", "Canada", "Cuba", "Guatemala"]

      });
 </script>


   <input class="countries" type="text" placeholder="Countries">

但是没有自动填充建议....我只是按照以下链接中的前两个步骤来完成我的任务......

http://www.arungudelli.com/jquery/simple-jquery-autocomplete-search-tutorial/

有任何帮助吗?

1 个答案:

答案 0 :(得分:0)

要准确说出您的设置发生了什么有点困难,但您不需要包含typeahead.min.js和typeahead.js。这个jsfiddle简化了你的一点点并且工作正常,所以它应该是一个好的起点。

<script type="text/javascript" src="http://twitter.github.io/typeahead.js/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="http://twitter.github.io/typeahead.js/releases/latest/typeahead.js"></script>

<input class="countries" type="text" placeholder="Countries">

<script type="text/javascript">
     $('input.countries').typeahead({
         name: 'countries',
         local: ["Unites States", "Mexico", "Canada", "Cuba", "Guatemala"]
     });
</script>