how to dynamically add options to an existing select in vanilla javascript

后端 未结 6 528
面向向阳花
面向向阳花 2020-11-29 20:16

I\'d like to add option to a select dynamically using plain javascript. Everything I could find involves JQuery or tries to create the select dynamically as well. The clos

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 20:28

    Try this;

       var data = "";
       data = "";         
       options = [];
       options.push(data);
       select = document.getElementById("drop_down_id");
       select.innerHTML = optionsHTML.join('\n'); 
    

提交回复
热议问题