0%

JavaScript将数组中的内容传输到select的下拉option中

JS代码:

1
2
3
4
5
6
7
8
9
10
11
<script>
var gSelectID = ["123","456",'789'];
for (var i in gSelectID) {
var selectID = document.getElementById("selectID");
var option = document.createElement("option");// 创建option元素
option.appendChild(document.createTextNode(gSelectID[i]));
option.setAttribute("value", gSelectID[i]);
selectID.appendChild(option);
}

</script>

html代码:

1
2
3
<div id="selectIdBox">
<select id="selectID"></select>
</div>