# 下拉选择框动态数据生成并加载
~~~
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
window.onload=loadData;
var datas=["南京","上海"];
function loadData()
{
alert(1);
var selectObj=document.getElementById("citys");
for(var i in datas)
{
var opObj=document.createElement("option");
opObj.setAttribute("value",datas[i]);
var node= document.createTextNode(datas[i]);
opObj.appendChild(node);
selectObj.appendChild(opObj);
}
}
</script>
</head>
<body>
<select id="citys">
<option value="-1">请选择城市</option>
</select>
</body>
</html>
~~~