日期:2014-05-16 浏览次数:20425 次
var sel=document.getElementById('select的id')
for(var i=0;i<json.length;i++)
sel.options.add(new Option(json[i].ItemName,json[i].ItemName))
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Test</title>
<script type="text/javascript">
var arr = [
{itemName: "南京1", id: 1},
{itemName: "南京2", id: 2},
{itemName: "南京3", id: 3},
{itemName: "南京4", id: 4},
{itemName: "南京5", id: 5},
];
function go(){
var htmlStr = "<select>";
for(var i=0; i<arr.length; i++){
var json = arr[i];
htmlStr += "<option value='" + json.id + "'>";
htmlStr += json.itemName;
htmlStr += "</option>";
}
htmlStr += "</select>";
var elem = document.getElementById("c");
elem.innerHTML = htmlStr;
}
window.onload = go;
</script>
</head>
<body>
<div id="c"></div>
</body>
</html>