js实现下拉框添加选项


感谢作者的无私分享!

版权声明:本文为博主原创文章,遵循 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);
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM