我无法弄清楚以下代码中的错误。如果输入任何字母,它不会显示下拉列表。如果有人能对此有所了解,我将非常感激。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Bootstrap typeahead example by w3resource</title>
<link href="bootstrap.css" rel="stylesheet" type="text/css" />
<script src="jquery.js"></script>
<script src="bootstrap-typeahead.js"></script>
</head>
<body>
<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>
</body>
</html>
答案 0 :(得分:0)
尝试不加引号:
data-source=["Ahmedabad","Akola","Asansol","Aurangabad","Bangaluru","Baroda","Belgaon","Berhumpur","Calicut","Chennai","Chapra","Cherapunji"]
答案 1 :(得分:0)
我认为问题是,传递给typeahead的源被认为是一个字符串,所以你需要在这里做一个html转义
<input type="text" class="span3" style="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Dakota","North Carolina","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]">
演示:Fiddle