js drop-down box to add options to achieve

The authors thank the selfless sharing!

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: HTTPS: //blog.csdn.net/weixin_43757001/article/details/91682494
HTML Code
<- - drop-down box to select the above mentioned id!>
<Div the above mentioned id = "selectIdBox">
<the SELECT the above mentioned id = "selectid"> < / SELECT>
</ div>

the JavaScript code that
var gSelectID = [ "001", "002", "003", " all"];
for (var I in gSelectID) {
var selectid = document.getElementById ( "selectid");
var option = document.createElement ( "option" ); // Create option element
option.appendChild (document.createTextNode (gSelectID [I]));
option.setAttribute ( "value", gSelectID [I]);
selectID.appendChild ( Option);
}

Guess you like

Origin www.cnblogs.com/huhewei/p/11980801.html