removing all option of dropdown box in javascript

后端 未结 7 1734
自闭症患者
自闭症患者 2021-02-01 04:21

How can i dynamically remove all options of a drop down box in javascript?

7条回答
  •  抹茶落季
    2021-02-01 05:02

    Setting the length to 0 is probably the best way, but you can also do this:

    var mySelect = document.getElementById("select");
    var len = mySelect.length;
    for (var i = 0; i < len; i++) {
        mySelect.remove(0);
    }
    

提交回复
热议问题