js数组如何将data的数据循环到下面的对应的select中
<scripttype="text/javascript">vardata=[{"AAA":{"id":"1","name":"asdfasdf"}},{"BBB":{"...
<script type="text/javascript">
var data=[
{"AAA":{"id":"1","name":"asdfasdf"}},
{"BBB":{"id":"1","name":"asdfasdf"}},
{"CCC":{"id":"1","name":"asdfasdf"}},
{"DDD":{"id":"1","name":"asdfasdf"}},
{"EEE":{"id":"1","name":"asdfasdf"}},
{"FFF":{"id":"1","name":"asdfasdf"}}
]
</script>
<select name="" id="AAA"></select>
<select name="" id="BBB"></select>
<select name="" id="CCC"></select>
<select name="" id="DDD"></select>
<select name="" id="EEE"></select>
<select name="" id="FFF"></select> 展开
var data=[
{"AAA":{"id":"1","name":"asdfasdf"}},
{"BBB":{"id":"1","name":"asdfasdf"}},
{"CCC":{"id":"1","name":"asdfasdf"}},
{"DDD":{"id":"1","name":"asdfasdf"}},
{"EEE":{"id":"1","name":"asdfasdf"}},
{"FFF":{"id":"1","name":"asdfasdf"}}
]
</script>
<select name="" id="AAA"></select>
<select name="" id="BBB"></select>
<select name="" id="CCC"></select>
<select name="" id="DDD"></select>
<select name="" id="EEE"></select>
<select name="" id="FFF"></select> 展开
展开全部
是不是这样
<select name="" id="AAA"></select>
<select name="" id="BBB"></select>
<select name="" id="CCC"></select>
<select name="" id="DDD"></select>
<select name="" id="EEE"></select>
<select name="" id="FFF"></select>
<script type="text/javascript">
var data=[
{"AAA":{"id":"1","name":"asdfasdf"}},
{"BBB":{"id":"1","name":"asdfasdf"}},
{"CCC":{"id":"1","name":"asdfasdf"}},
{"DDD":{"id":"1","name":"asdfasdf"}},
{"EEE":{"id":"1","name":"asdfasdf"}},
{"FFF":{"id":"1","name":"asdfasdf"}}
];
for(var i=0;i<data.length;i++){
for(var key in data[i]){
var obj=document.getElementById(key);
if(obj){
obj.innerHTML='<option value="'+data[i][key].id+'">'+data[i][key].name+'</option>';
}
}
}
</script>
追问
已经解决了。谢谢
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询