Javascript - innerHTML not working with HTML select menus

后端 未结 8 1416
眼角桃花
眼角桃花 2020-11-30 15:18

In my HTML page I have 2 select menus with IDs \"month\" and \"day\" - \"day\" is empty when the page loads, \"month\" has 12 options with values 1-12 corresponding to Janua

8条回答
  •  情深已故
    2020-11-30 15:33

    I came to this question and wanted to share my problem/answer hoping it may help others.

    I had this which did not work:

    function change_select() {
        var sel = document.getElementById('my-id').innerHTML;
        sel = '';
    }
    

    I changed it to this which did work:

    function change_select() {
        var sel = document.getElementById('my-id');
        sel.innerHTML = 'option>new item';
    }
    

提交回复
热议问题