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

后端 未结 6 527
面向向阳花
面向向阳花 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:30

    I guess something like this would do the job.

    var option = document.createElement("option");
    option.text = "Text";
    option.value = "myvalue";
    var select = document.getElementById("daySelect");
    select.appendChild(option);
    

提交回复
热议问题