2013-12-19 39 views
0

在Index.cshtml,我有下面的代碼:在ASP.NET MVC使用Twitter Typehead

@{ 
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"> 

但沒有自動完成建議....我只是跟隨第一2步在下面的鏈接做我的任務......

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

有什麼幫助嗎?

+0

如果您根據該頁面上的評論進行調整,這是否可行? 'input.countries'而不是'input.counties'? –

+0

謝謝丹尼爾...絕對是錯誤的...我糾正了它。但是我仍然有同樣的問題 –

+0

你是否包含typeahead.js庫文件?本教程沒有提到它,但沒有它,你不會走得很遠。 – Dhaulagiri

回答

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> 
+0

謝謝你介紹jsfiddle ...我會進一步探索。大多數情況下,我認爲我可以通過試驗jsfiddle來解決問題... –

+0

這就是我發現的最佳效果。這個庫可能很難使用,因爲當它不能按照你期望的方式工作時,它不會給你太多的幫助。 – Dhaulagiri