Adding options to a select and selecting one on internet explorer

后端 未结 3 1940
梦如初夏
梦如初夏 2021-01-15 01:02

I have a select, and I am filling the options using javascript. Something like

    var select = document.getElementById(\"selectBox\");

    for (var i = 0;          


        
3条回答
  •  迷失自我
    2021-01-15 01:52

    Use add instead of appendChild:

    select.add(option);
    

    Also, using the Option constructor can save you some lines of code:

    var option = new Option(data[i].name, data[i].id);
    

提交回复
热议问题