js实现下拉框添加选项

梦想的初衷 提交于 2019-12-06 11:41:13

感谢作者的无私分享!

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_43757001/article/details/91682494
html代码
<!-- 下拉框选择id -->
<div id="selectIdBox">
<select id="selectID"></select>
</div>

JavaScript代码
var gSelectID = ["001", "002", "003", "全部"];
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);
}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!