最初,我生成了一个dropdown menu
:
我添加了有关如何制作下拉菜单的更多详细信息。
<div class="well sidebar-nav">
<img src="building.gif" style="display: block;margin-left:auto; margin-right:auto;max-width:100%; max-height:100%;" />
<div class="dropdown" style="padding-left: 20px; padding-top:5px;">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" style="display: block;margin-left:auto; margin-right:auto;">
Select A Building
<span class=" caret">
</span>
</button>
<ul id="myul" class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1"></ul>
</div>
</div>
</div><!--/span2-->
现在,我编写了以下代码:
var buildingList=[
{
"BuildingName": "Adler Journalism and Mass Communication Building",
"BuildingNumber": "0456"
},
{
"BuildingName": "Art Building",
"BuildingNumber": "0021"
}
];
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" style="display: block;margin-left:auto; margin-right:auto;">
Select A Building
<span class=" caret">
</span>
</button>
<ul id="myul" class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
</ul>
<script type="text/javascript">
var out = "";
var ul = document.getElementById("myul");
for (i = 0; i < buildingList.length; i++) {
out = ' <li role="presentation"><a role="menuitem" tabindex="-1" href=" ' + buildingList[i].BuildingName + ' "> ' + buildingList[i].BuildingName + ' </a></li>';
var li = document.createElement("li");
var t = document.createTextNode(out);
li.appendChild(t);
ul.appendChild(li);
}
</script>
我想dropdown
根据buildingList
数组动态生成一个列表javascript
,你能帮帮我吗?
提前致谢!