预先输入不填充数据源

时间:2014-03-20 17:36:36

标签: javascript jquery typeahead.js

<div class="well">  
<input type="text" class="span3" style="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="["Ahmedabad","Akola","Asansol","Aurangabad","Bangaluru","Baroda","Belgaon","Berhumpur","Calicut","Chennai","Chapra","Cherapunji"]">  
</div>  

我已添加内联数据源。

检查此小提琴链接:http://jsfiddle.net/5WjHR/

它不会自动填写输入框中的数据。

Typeahead JS&amp; Bootstrap CSS已作为外部资源添加到小提琴中。

2 个答案:

答案 0 :(得分:1)

必须使用单引号和双引号组合,否则必须对它们进行转义。

<input type="text" class="span3" style="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source='["Ahmedabad","Akola","Asansol","Aurangabad","Bangaluru","Baroda","Belgaon","Berhumpur","Calicut","Chennai","Chapra","Cherapunji"]'>

演示:http://jsfiddle.net/5WjHR/2/

答案 1 :(得分:1)

将数据源双引号更改为单引号应该有效:)

http://jsfiddle.net/aamir/5WjHR/1/

data-source='["Ahmedabad","Akola","Asansol","Aurangabad","Bangaluru","Baroda","Belgaon","Berhumpur","Calicut","Chennai","Chapra","Cherapunji"]'